服务端:ObjectOutputStreamoos=newObjectOutputStream(socket.getOutputStream()FileInputStreamfis=newFileInputStream(fileName)byte[]b=newbyte[512];intlen;NetDatanetData=newN...
服务端:
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()
FileInputStream fis=new FileInputStream(fileName)
byte[] b = new byte[512];
int len;
NetData netData=new NetData();
while ((len = input.read(b)) != -1) {
netData.data=b;
netData.len=len;
oos.writeObject(netData);
}
客户端:
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream()
FileOutputStream fos=new FileOutputStream(fileName);
NetData netData;
while ((netData =(NetData)ois.readObject()) != null) {
fos.writeObject(netData.data,0,netData.len);
}
省略了许多无关代码,能正常传送文件,文件大小也一样,但,文件内容却不相同,不知道是为什么?????
文件是一张图片,传送过去大小是一样的,但打不开,换成其他文件也一样
展开