[英]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中多線程的基礎知識
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.