public static void main(String[] args) throws IOException {
ServerSocket ss= new ServerSocket(8800);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
InputStream is = s.getInputStream();
File dir =new File("c:\\pic");
if(!dir.exists()){
dir.mkdirs();
}
File file = new File(dir, ip+".bmp");
FileOutputStream fos = new FileOutputStream(file);
byte[]buf = new byte[1024];
int len = 0;
while(((len=is.read(buf))!=-1)){
fos.write(buf, 0, len);
}
OutputStream out = s.getOutputStream();
out.write("上传成功".getBytes());
fos.close();
ss.close();
}
}
服务端没事。客户端我基本按照老毕的视频写的,只有最后读取服务端回传信息时用了bufferedreader,视频中用的是inputstream
请问我这么写有哪里不对吗?总是报Exception in thread "main" java.net.SocketException: Connection reset异常