我正在尝试构建一个使用 DataInputStream 和 BufferedInputStream 从客户端接收文件的服务器程序。
这是我的代码,它陷入了无限循环,我认为这是因为没有使用 available() 但我不太确定。
DataInputStream din = new DataInputStream(new BufferedInputStream(s.getInputStream()));
//s is socket that connects fine
fos = new FileOutputStream(directory+"/"+filename);
byte b[] = new byte[512];
int readByte = din.read(b);
while(readByte != 1){
fos.write(b);
readByte = din.read(b);
//System.out.println("infinite loop...");
}
谁能告诉我为什么它陷入无限循环?如果是因为没有使用 available ,请告诉我如何使用它?我实际上用谷歌搜索,但我对用法感到困惑。非常感谢