import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class TcpService {
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
try{
ServerSocket ss=new ServerSocket(8001);//运行上面代码提示以下信息:java.net.BindException: Address already in use: JVM_Bind
Socket s=ss.accept();
FileWriter fw=new FileWriter("d:/tt.txt");
BufferedWriter bw=new BufferedWriter(fw);
for(int i=0;i<10;i++){
bw.write("Line"+i+"\n\r");
}
bw.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
注:第一次编译的时候没有出错,而且已成功向指文件中输入了代码。 |