[英]Server sending Empty file to client
服務器端代碼
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();
客戶端代碼
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();
我正在從服務器到客戶端獲取一個空文件。 即使在服務器上它正在打印不為零的字節數組大小。 誰能幫我這個忙嗎?
我正在從服務器到客戶端獲取一個空文件。
使用該代碼,文件在服務器上也必須為空。
即使在服務器上它正在打印不為零的字節數組大小。
那是因為您將其初始化為“新字節[1024]”。 它與文件的長度無關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.