//暮雪超霸、加油!!!
package tcp文本上传;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class UploadClient {
public static void main(String[] args) throws UnknownHostException, IOException {
Socket s=new Socket("127.0.0.1", 10008);
BufferedReader bufIn=new BufferedReader(new FileReader("chaoba.txt"));
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
String line=null;
while((line=bufIn.readLine())!=null){
pw.println(line);
}
s.shutdownOutput();
BufferedReader buf=new BufferedReader(new InputStreamReader(s.getInputStream()));
String readLine = buf.readLine();
System.out.println(readLine);
bufIn.close();
s.close();
}
}
package tcp文本上传;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class UploadServer {
public static void main(String[] args) throws IOException {
ServerSocket ss=new ServerSocket(10008);
Socket accept = ss.accept();
BufferedReader bufIn =new BufferedReader(new InputStreamReader(accept.getInputStream()));
String line=null;
BufferedWriter bufw=new BufferedWriter(new FileWriter("server.txt"));
while((line=bufIn.readLine())!=null){
bufw.write(line);
bufw.newLine();
bufw.flush();
}
PrintWriter pw=new PrintWriter(accept.getOutputStream(),true);
pw.println("上传成功");
bufw.close();
accept.close();
ss.close();
}
}