I have multiples html files in a folder : the code below list all of them and then parse them with Jsoup : I don't succeed to write the results of all these files parsed with Jsoup to a text file : I only get the result of the last file that was parsed. What's wrong ?
The code is :
package jsouppackage;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Main {
public static void main(String[] args) {
File input = new File("C:/html");
File[] st = input.listFiles();
for (int i = 0; i < st.length; i++) {
if(st[i].isFile()){
parse(st[i]);
}
}
}
private static void parse(File input ) {
Document doc;
try{
doc = Jsoup.parse(input, "UTF-8", "");
Elements ids = doc.select("div[id^=osdi] p");
PrintWriter out = new PrintWriter("C:/html/output/output.txt", "UTF-8");
for (Element id : ids){
out.println("\n"+id.text());
}
out.close();
}catch(IOException e){
}
}
}
Thanks for your help