簡體   English   中英

如何處理一組網址而不是每次一個網址?

[英]how to process a set of urls instead of one url per time?

讓我說我有一個網址列表,如

http://stackexchange.com
https://stackoverflow.com/users/login
http://careers.stackoverflow.com
http://chat.stackoverflow.com
http://meta.stackoverflow.com
https://stackoverflow.com/about

此列表位於文本文件中。

現在我想一次性處理所有的網址。 以下編碼是處理器。

String sourceUrlString="http://stackexchange.com";
    if (args.length==0)
      System.err.println("Using default argument of \""+sourceUrlString+'"');
    else
        sourceUrlString=args[0];
    if (sourceUrlString.indexOf(':')==-1) sourceUrlString="file:"+sourceUrlString;
    Source source=new Source(new URL(sourceUrlString));
    String renderedText=source.getRenderer().toString();
    System.out.println("\nSimple rendering of the HTML document:\n");
    System.out.println(renderedText);

如你所見,上面的編碼只能處理一個url,我必須手動鍵入sourceurlstring的url。 如何一次處理文本文件中的所有網址?

  • 通過閱讀Java教程的這一部分,了解哪些方法。
  • 實現一個方法,將一個URL作為參數並進行處理。
  • 通過閱讀Java教程的這一部分,了解如何閱讀文本文件。
  • 實現一種逐行讀取文本文件的方法,並為文件中讀取的每一行調用第一種方法。

您需要利用多線程。

這應該讓您開始正確的道路: Java中多線程的基礎知識

暫無
暫無

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

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