java.net.SocketException: Connection reset 20
publicclassClient{publicstaticvoidmain(Stringargs[])throwsException,IOException{Strin...
public class Client {
public static void main(String args[]) throws Exception,IOException {
String host = "127.0.0.1";
int port = 8899;
Socket client = new Socket(host, port);
PrintWriter writer = new PrintWriter(new OutputStreamWriter (client.getOutputStream()),true);
File file = new File("test.xml"); //用于发送的文件路径
BufferedReader reader = new BufferedReader(new FileReader(file));
String str=null;
while((str = reader.readLine()) != null)
writer.println(str);
writer.flush();
BufferedReader br=new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("result.xml",false)));
String st=null;
while((st=br.readLine())!=null){// br.reandLine()这 报错
out.println(st);
}
out.flush();
out.close();
writer.close();
reader.close();
client.close();
}
}
public class Server {
public static void main(String args[]) throws Exception {
String URL="query.xml";
int port = 8899;
ServerSocket server = new ServerSocket(port);
Socket socket = server.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(URL,false)));
String str=null;
String xml=new String();
while((str = br.readLine()) != null){
xml+=str+"/n";
out.println(str);
}
out.flush();
System.out.println(xml);
PrintWriter writer = new PrintWriter(new OutputStreamWriter (socket.getOutputStream()),true);
File file = new File("ser.xml"); //用于发送的文件路径
BufferedReader reader = new BufferedReader(new FileReader(file));
String stre=null;
while((stre = reader.readLine()) != null){
System.out.println(stre);
writer.println(stre);}
writer.flush();
writer.close();
reader.close();
out.close();
socket.close();
server.close();
}
}
错误好像在Client 中的br.readLine()处,怎么解决??? 展开
public static void main(String args[]) throws Exception,IOException {
String host = "127.0.0.1";
int port = 8899;
Socket client = new Socket(host, port);
PrintWriter writer = new PrintWriter(new OutputStreamWriter (client.getOutputStream()),true);
File file = new File("test.xml"); //用于发送的文件路径
BufferedReader reader = new BufferedReader(new FileReader(file));
String str=null;
while((str = reader.readLine()) != null)
writer.println(str);
writer.flush();
BufferedReader br=new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("result.xml",false)));
String st=null;
while((st=br.readLine())!=null){// br.reandLine()这 报错
out.println(st);
}
out.flush();
out.close();
writer.close();
reader.close();
client.close();
}
}
public class Server {
public static void main(String args[]) throws Exception {
String URL="query.xml";
int port = 8899;
ServerSocket server = new ServerSocket(port);
Socket socket = server.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(URL,false)));
String str=null;
String xml=new String();
while((str = br.readLine()) != null){
xml+=str+"/n";
out.println(str);
}
out.flush();
System.out.println(xml);
PrintWriter writer = new PrintWriter(new OutputStreamWriter (socket.getOutputStream()),true);
File file = new File("ser.xml"); //用于发送的文件路径
BufferedReader reader = new BufferedReader(new FileReader(file));
String stre=null;
while((stre = reader.readLine()) != null){
System.out.println(stre);
writer.println(stre);}
writer.flush();
writer.close();
reader.close();
out.close();
socket.close();
server.close();
}
}
错误好像在Client 中的br.readLine()处,怎么解决??? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询