2013-05-08 79 views
0

我使用下面的代碼,以獲取來自Web的圖片:jsoup意外獲取shopwiki圖像

import java.io.FileOutputStream; 
import java.io.IOException; 

import org.jsoup.Jsoup; 

public class fetchImageTest { 
    public static void main(String[] args) throws Exception {  
     saveImage(args[0], args[1]); 
    } 

    private static boolean saveImage(String string, String destination) throws IOException { 

     string = string.replaceAll(" ", "%20"); 

     try { 
      byte[] image = Jsoup.connect(string).ignoreContentType(true).timeout(10000).execute().bodyAsBytes(); 

      FileOutputStream os = new FileOutputStream(destination); 

      os.write(image);   
      os.close(); 

      return true; 
     } 

     catch (IOException e) { 
      System.out.println("couldn't open " + string); 
      return false; 
     } 

     catch (Exception e) { 
      System.out.println("couldn't open - general exception" + string); 
      return false; 
     } 
    } 
} 

由於我的一些其他代碼中的錯誤,我試圖從一個破碎的URL抓取圖像,形式:

http://shop.foo.comhttp://shop.foo.com/1.jpg 

我的代碼最終取出一個shopwiki圖像,像shopwiki-image

我使用jsoup-1.7.1.jar。我的服務器上有病毒嗎?我的jsoup jar文件是否有病毒?

我真的不知道......

回答