问一个关于javac我的程序时出现的问题(我写的类继承了Thread类).求解!谢谢!
package c8;
import java.lang.Thread;
import java.io.BufferedReader;
import
java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.
UnknownHostException;
public class Scan extends Thread {
private int port;
private static String serverIP;
public Scan(int port) {
this.port = port;
}
public void run() {
try {
Socket socket = new Socket(serverIP, port);
System.out.println(port);
socket.close();
} catch (UnknownHostException e) {
System.out.println( "this port is close ");
} catch (
IOException e) {
System.out.print( " ");
}
}
public static String doread() {
String s = null;
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
s = bf.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
public static void main(String[] args) {
System.out.println( "请输入你要扫描的主机IP ");
serverIP = Scan.doread();
System.out.println( "主机 "+serverIP+ "开放的TCP端口有: ");
for (int i = 0; i < 1500; i++) {
Scan scan = new Scan(i);
Thread thread = new Thread(scan);
thread.start();
}
System.out.println( "端口已经扫描完毕 ");
}
}
以上是我在Eclipse中写的一个程序,功能是扫描服务器开发的端口号。
现在我想在命令行用javac命令来实现对程序的运行,但总是提示说找不到我的Thread类,于是我就将我的这个Scan.java程序放到我JDK的C:\Program Files\Java\jdk1.5.0_07目录下,为了能使import java.lang.Thread;能将Thread类找到~但是试了还是不行~
想问下我上面的程序前面的:
package c8;
import java.lang.Thread;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
这些要不要呢~?要不行该怎么样做呢~?谢谢~有点急!!!在线等~
------解决方案--------------------Thread thread = new Thread(scan);这个有问题。你的构造函数是int类型,但是这里scan是个类对象吧,而且scan是继承thread的,建立对象时候
int xx=Integer.parseInt(serverIP);//将字符串转化为整数
Scan scan=new Scan(xx);
sacn.start();