import java.io.*;
import java.net.Socket;
public class SocketThread implements Runnable{
private Socket s;
private int count=0;
public SocketThread(Socket s) {
this.s = s;
}
@Override
public void run() {
try {BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
File file = new File("E:\\develop\\sunyixiang\\a[" + count + "].txt");
while (file.exists()){
file=new File("E:\\develop\\sunyixiang\\a[" + (++count) + "].txt");
}
file.createNewFile();
BufferedWriter bw1=new BufferedWriter(new FileWriter(file));
String str;
while ((str=br.readLine())!=null){
bw1.write(str);
bw1.newLine();
bw1.flush();
}
bw.write("数据接收成功");
bw.flush();
//s.shutdownOutput();
s.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} |
|