【发布时间】:2016-02-03 13:24:18
【问题描述】:
我正在尝试解析一些链接,然后将信息存储在文本文件中,我将所有应该解析的链接放在一个列表中,但是在解析和存储有关 100 个链接的信息后,我得到了我真的无法理解的错误为什么会发生,这是我的代码:
for(String link : links){
Document doc = Jsoup.connect(link).get();
Element e1 = doc.select("h1").first();
String authorName = e1.ownText();
String fileName = authorName.replaceAll("\\s+","");
PrintWriter writer = new PrintWriter("/home/taner/Test/"+fileName+".txt", "UTF-8");
String description = doc.getElementsByClass("article__content").text();
writer.write(description);
writer.close();
}
这就是我得到的错误:
Exception in thread "main" java.io.FileNotFoundException: /home/taner/Test/MarcusSchmidt/JohannaDrott.txt (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
at java.io.PrintWriter.<init>(PrintWriter.java:192)
at java.io.PrintWriter.<init>(PrintWriter.java:232)
at Test1.main(Test1.java:253)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
第 253 行实际上是 PrintWriter writer = new PrintWriter("/home/taner/Test/"+fileName+".txt", "UTF-8"); 行
【问题讨论】:
标签: java html parsing printwriter