簡體   English   中英

我如何在Jsoup getImages方法上添加第二個參數

[英]How can i add a second argument on Jsoup getImages method

我正在使用下面的方法從網站檢索圖像,並且我想為每個圖像添加唯一的ID。

我怎樣才能做到這一點。

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();
}

我找到了遮陽篷:

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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM