[英]Jsoup and saving to text file
It could be easy, but I don't know how to do.这可能很容易,但我不知道该怎么做。
Elements rows = table.select("tr");
String s[] = new String[rows.size()];
String p[] = new String[rows.size()];
for (int i = 1; i < rows.size(); i++) {
Element row = rows.get(i);
Elements cols = row.select("td");
s[i] = cols.get(0).text();
p[i] = cols.get(1).text();
String c = s[i] + ":" + p[i];
list1.add(c);
out.print(c); // not work; blank text document.
So I need to write string c to txt file.所以我需要将字符串 c 写入 txt 文件。 Everything I got is a blank txt file.
我得到的一切都是一个空白的txt文件。 I tried with cols.text() it worked, but writes all table body to txt file.
我尝试使用 cols.text() 它有效,但将所有表体写入 txt 文件。
Ok, i found solution :好的,我找到了解决方案:
Elements rows = table.select("tr");
String s[] = new String[rows.size()];
String p[] = new String[rows.size()];
boolean connectionStatus=false;
for (int i = 1; i < rows.size(); i++) {
Element row = rows.get(i);
Elements cols = row.select("td");
s[i] = cols.get(0).text();
p[i] = cols.get(1).text();
String c = s[i] + ":" + p[i];
list1.add(c);
out.print(c);
out.print(System.getProperty("line.separator"));
out.flush(); // add flush in loop
}
out.close(); // close
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.