import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
public class ServerThread implements Runnable {
private Socket s;
public ServerThread(Socket s) {
this.s =s;
}
@Override
public void run() {
int count = 0;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
File file = new File("InetAddress\\Copy["+count+"].java");
while (file.exists()){
count++;
file = new File("InetAddress\\Copy["+count+"].java");
}
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
String line;
while ((line=br.readLine())!=null){
bw.write(line);
bw.newLine();
bw.flush();
BufferedWriter bwServer = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bwServer.write("上传文件成功");
bwServer.newLine();
bwServer.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
|