简体   繁体   中英

Server sending Empty file to client

Server Side code

int count=-1;
byte [] mybytearray  = new byte [1024];

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile));
os = s.getOutputStream();

System.out.println("Sending " + fileName + "(" + mybytearray.length + " bytes)");
while( (count=(bis.read(mybytearray)))>0) {
    System.out.println(count);
    os.write(mybytearray,0,count);
    os.flush();
}
System.out.println("Done.");                      
bis.close(); 
os.close();

Client Side code

int bytesRead=-1;
byte [] mybytearray  = new byte [1024];
InputStream isP = p2p.getInputStream();
 FileOutputStream fos = new FileOutputStream(path+"RFC "+rfcNum+".txt");
while((bytesRead=isP.read(mybytearray))>0) {
fos.write(mybytearray, 0, bytesRead);
fos.flush();
fileSize+=bytesRead;
 } 
System.out.println("file Size is "+fileSize);
isP.close();
fos.close();

i am getting an empty file from server to client . Even though at the server it is printing the the bytearray size which is not zero. Can anyone please help me with this?

i am getting an empty file from server to client.

With that code, the file must be empty at the server too.

Even though at the server it is printing the the bytearray size which is not zero.

That's because you initialized it as 'new byte[1024]'. It has nothing to do with the length of the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM