import java.io.*;
import java.net.*;;
class Client{
public static void main(String[] args) throws IOException, Exception{
Socket s = new Socket("192.168.56.29", 10006);
BufferedReader bufr = new BufferedReader(new FileReader("demo.java"));
PrintWriter pw = new PrintWriter(s.getOutputStream(),true);
String data = null;
while((data = bufr.readLine()) != null){
pw.println(data);
}
s.shutdownOutput();
BufferedReader bufin = new BufferedReader(new InputStreamReader(s.getInputStream()));
String ss = bufin.readLine();
System.out.println(ss);
bufr.close();
s.close();
}
}
class Server{
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(10006);
Socket s = ss.accept();
BufferedReader bufr = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(new FileWriter("copy.java"),true);
String line = null;
while((line=bufr.readLine()) != null){
out.println(line);
}
out.close();
BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bufw.write("上传成功");
bufw.close();
bufr.close();
s.close();
ss.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
就是按照老毕的视频写的代码,但是复制文件后新的文件总是多一行,怎么解决 |
|