客户端的代码
public class Client {
public static void main(String[] args) throws Exception {
Socket socket = new Socket(InetAddress.getByName("192.168.1.105"), 7788);
File file = new File("f:/123.jpg");
FileInputStream fis = new FileInputStream(file);
OutputStream os = socket.getOutputStream();
int len = 0;
byte[] buffer = new byte[1024];
while ((len = fis.read(buffer)) != -1) {
os.write(buffer, 0, len);
os.flush();
}
fis.close();
socket.close();
}
}
服务端的代码
public class Server {
public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(7788);
Socket s = ss.accept();
BufferedInputStream bis = new BufferedInputStream(s.getInputStream());
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream("d:/456.jpg"));
byte[] buffer = new byte[1024];
int len = 0;
while ((len = bis.read(buffer)) != -1) {//报错显示这里有问题
bos.write(buffer, 0, len);
bos.flush();
}
bos.close();
s.close();
ss.close();
}
}
我不知道哪里错了 报错信息
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at Server.main(Server.java:16)
|
|