结果是客户端错误 求指教哪里错误了
Socket s =null;
BufferedReader bufr =null;
PrintWriter out =null;
BufferedReader bufin =null;
try
{
s =new Socket("192.168.0.101",2222);
bufr =new BufferedReader(new FileReader("d:\\9.txt"));
out =new PrintWriter(s.getOutputStream(),true);
bufin =new BufferedReader(new InputStreamReader(s.getInputStream()));
String line =null;
while((line=bufr.readLine())!=null)
{
out.println(line);
}
s.shutdownOutput();
String len =bufin.readLine();
System.out.println(len);
}
catch(Exception e)
{
System.out.println("客户端错误!");
}
finally
{
if(s!=null)
try
{
s.close();
}
catch(Exception e)
{
System.out.println("客户端关闭错误!");
}
if(bufr!=null)
try
{
bufr.close();
}
catch(Exception e)
{
System.out.println("输入流关闭错误!");
}
}
ServerSocket ss =null; Socket s =null; BufferedReader bufr =null; PrintWriter out =null; PrintWriter pw =null; try { ss = new ServerSocket(2222); s =ss.accept(); String ip =s.getInetAddress().getHostAddress(); System.out.println(ip+".......is connected"); out =new PrintWriter(s.getOutputStream(),true); bufr =new BufferedReader(new InputStreamReader(s.getInputStream())); pw =new PrintWriter(new FileWriter("d:\\online.txt")); String line =null; while((line=bufr.readLine())!=null) { pw.println(line); } out.println("上传成功"); } catch(Exception e) { System.out.println("服务端错误"); } finally { try { if(pw!=null) pw.close(); } catch(Exception e) { System.out.println("客户端关闭错误"); } try { if(s!=null) s.close(); } catch(Exception e) { System.out.println("客户端关闭错误"); } try { if(ss!=null) ss.close(); } catch(Exception e) { System.out.println("服务端关闭错误"); } }
|
|