黑马程序员技术交流社区
标题:
学习笔记
[打印本页]
作者:
梦付千秋星垂野
时间:
2019-10-10 19:03
标题:
学习笔记
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();
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2