客户端:
public class TextSendClient {
public static void main(String[] args) throws Exception{
Socket s=new Socket("172.27.35.1",10006);
BufferedReader br=new BufferedReader(new FileReader("f://a.txt"));
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
String line=null;
while((line=br.readLine())!=null){
pw.println(line);
}
//关闭客户端的输出流,相当于给流中加入一个特殊标记
s.shutdownInput();
BufferedReader bufin=new BufferedReader(new InputStreamReader(s.getInputStream()));
String str=bufin.readLine();
System.out.println("server:"+str);
s.close();
br.close();
}
}
服务器端:
public class TextReceiveServer {
public static void main(String[] args)throws Exception {
ServerSocket ss=new ServerSocket(10006);
Socket s=ss.accept();
String ip=s.getInetAddress().getHostAddress();
System.out.println(ip+".....connected");
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter pw=new PrintWriter(new FileWriter("f://serer.txt"),true);
String line=null;
while((line=br.readLine())!=null){
pw.println(line);
}
PrintWriter pwr=new PrintWriter(s.getOutputStream(),true);
pwr.println("上传成功");
s.close();
ss.close();
pw.close();
}
}
最后结果,是文件内容复制成功,但是并没有输出,上传成功,而且会
出现
java.net.SocketException: Connection reset 求大神指导一下是怎么回事该怎么解决
|
|