2017-07-06 8 views
0

私は以下のメソッドを使用してWebサイトから画像を取得していますが、各画像に一意のIDを追加します。Jsoup getImagesメソッドに2番目の引数を追加するにはどうすればいいですか

どうすればいいですか?

private static void getImages(String src) throws IOException { 
    String folder = null; 

    //Exctract the name of the image from the src attribute 
    int indexname = src.lastIndexOf("/"); 
    if (indexname == src.length()) { 
     src = src.substring(1, indexname); 
    } 

    indexname = src.lastIndexOf("/"); 
    String name = src.substring(indexname, src.length()); 
    System.out.println(name); 

    //Open a URL Stream 
    URL url = new URL(src); 
    InputStream in = url.openStream(); 

    OutputStream out = new BufferedOutputStream(new FileOutputStream(folderPath+ name)); 
    for (int b; (b = in.read()) != -1;) { 
     out.write(b); 
    } 
    out.close(); 
    in.close(); 
} 

答えて

0

私はawnserが見つかりました:

private static void getImages(String src,String UrName) throws IOException { 
    String folder = "Folder url"; 

    //Exctract the name of the image from the src attribute 
    int indexname = src.lastIndexOf("/"); 
    if (indexname == src.length()) { 
     src = src.substring(1, indexname); 
    } 

    //Open a URL Stream 
    URL url = new URL(src); 
    InputStream in = url.openStream(); 

    OutputStream out = new BufferedOutputStream(new FileOutputStream(folderPath+ "/" +UrName+ ".jpg")); 

    for (int b; (b = in.read()) != -1;) { 
     out.write(b); 
    } 
    out.close(); 
    in.close(); 
} 
関連する問題