2015-11-12 104 views
1

我想下載一個使用Java的動畫gif圖像,但下載的圖像會丟失動畫。這是我的代碼:下載Java中的動畫gif圖像

BufferedImage image = ImageIO.read(new URL("http://gifntext.com/images/football_small.gif")); 
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 
    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream); 
    image.flush(); 
    ImageIO.write(image, "gif", bufferedOutputStream); 
    bufferedOutputStream.flush(); 

    byte[] bytes = outputStream.toByteArray(); 
    File file = new File("/home/toan/football_small.gif"); 
    FileOutputStream out = new FileOutputStream(file); 

    out.write(bytes); 
    out.flush(); 
    out.close(); 
    outputStream.close(); 
    bufferedOutputStream.close(); 

這段代碼有什麼問題嗎? 在此先感謝。

+1

我很好奇,爲什麼用'ImageIO'如果你只是想下載一個文件? – mzc

+0

你有任何建議嗎?謝謝。 – toandv

+1

http://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java – mzc

回答