网络编程上传复制图片在这里插入代码片
为什么显示上传成功却没有操作呢
public class My02Service {
public static void main(String[] args) {
try {
ServerSocket serverSocket=new ServerSocket(5555);
Socket socket = serverSocket.accept();
InputStream is = socket.getInputStream();
File file=new File("E:YingYi");
if (!file.exists()){
file.mkdirs();
}
FileOutputStream fos=new FileOutputStream(file+"\\20200420d01.png");
int len=0;
byte[] bytes=new byte[1024];
while ((len=is.read(bytes))!=-1){
fos.write(bytes,0,len);
}
socket.getOutputStream().write("上传成功".getBytes());
fos.close();
socket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```public class My02Client {
public static void main(String[] args) {
try {
FileInputStream fis= new FileInputStream("E:\\YingYi\\00043128_hhr.jpg");
Socket socket=new Socket("127.0.0.1",5555);
OutputStream os = socket.getOutputStream();
int len =0;
byte[] bytes=new byte[1024];
while ((len=fis.read(bytes))!=-1){
os.write(bytes,0,len);
}
socket.shutdownOutput();
InputStream is = socket.getInputStream();
while ((len=is.read(bytes))!=-1){
System.out.println(new String(bytes,0,len));
}
/*os.close();
is.close();*/
socket.close();
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}