所以我想要做的是从" UsernameList.txt"并以某种方式让它做这样的事情
文件中的文字:
construct
Hustle
savior
power
Revenge
阅读第一行,连接,同时阅读第二行做同样的事情。这可能吗?怎么可能这样做?
public class main {
public static void main(String[] args) throws IOException, InterruptedException {
BufferedReader fileR = new BufferedReader(new FileReader("UsernameList.txt"));
String line = null;
while ((line = fileR.readLine()) != null) {
Document doc = Jsoup.connect("https://twitter.com/" + line).get();
doc.html();
}
}
}
答案 0 :(得分:1)
你可以这样做。
public class Tester implements Runnable {
String line = null;
public static void main(String[] args) throws IOException {
BufferedReader fileR = new BufferedReader(new FileReader("UsernameList.txt"));
String line = null;
while ((line = fileR.readLine()) != null) {
Tester tester = new Tester();
tester.line = line;
Thread thread = new Thread(tester);
thread.start();
}
}
@Override
public void run() {
Document doc = Jsoup.connect("https://twitter.com/" + line).get();
doc.html();
}
}
答案 1 :(得分:0)
您可以拥有实现Callable的线程,该线程接受关键字connect并响应所需数据。您还可以使用Executor框架来控制一次运行的线程数。