[問題] 有人遇過EOFException(寫網頁抓圖程式)
下面這段函式用來抓取網頁的圖片,
剛開始測試一兩張抓取沒問題,
但是之後會出現EOFException的錯誤。
上網查詢聽說和Buffer設定有關,
不知道哪位高手可以解決?
public static void downloadPic(String picUrl) {
try {
URL url = new URL(picUrl);
URLConnection uc = url.openConnection();
DataInputStream dis = new DataInputStream(uc.getInputStream());
FileOutputStream fo = new FileOutputStream("D:\\test.jpg");
while (dis.available() != -1) // throws EOFException at ending stream.
{
fo.write(dis.readByte());
fo.flush();
}
dis.close();
fo.close();
System.out.println("complete.");
} catch (Exception e) {
System.out.print(e);// handle here
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.157.8
推
11/27 22:11, , 1F
11/27 22:11, 1F
推
11/28 05:38, , 2F
11/28 05:38, 2F
推
11/28 09:20, , 3F
11/28 09:20, 3F