我不知道为什么会出现java.io.EOFException。我想从服务器获取二进制流后写入文件。尝试从套接字读取时发生java.io.EOFException
这里是我的代码
inputStream = new DataInputStream(new BufferedInputStream(connection.getInputStream()));
FileOutputStream fos = new FileOutputStream("D:/Apendo API resumable download.txt");
byte b = inputStream.readByte();
while(b != -1){
fos.write(b);
b = inputStream.readByte();
}
fos.close();
堆栈跟踪
java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at HttpRequestJSON.JSONRequest.sendRequest(JSONRequest.java:64)
at HttpRequestJSON.Main.main(Main.java:56)
你在哪一行得到异常? –
当b = inputStream.readByte();在while(b!= -1) – Yusuf1494
错误,那就是当试图从*文件实际读取时。 – EJP