-1

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. Everything I got is a blank txt file. I tried with cols.text() it worked, but writes all table body to txt file.

darius
  • 47
  • 3
  • I can't reproduce your problem using posted code, but something tells me that you may not be closing `out` in your code. – Pshemo Feb 09 '17 at 20:05
  • Based on your answer your question is yet another duplicate of question like [BufferedWriter not writing everything to its output file](http://stackoverflow.com/q/13426142/1393766). Rule is same for all Writers or OutputStreams which can be used along with buffer. Getting permission to write to resource can take a lot of time, so we don't want to ask for it often. So we are storing large amount of data and then asking for permission to write. Writing happens automatically when buffer is full. In other case we need to call flush/close explicitly. – Pshemo Feb 09 '17 at 20:35

1 Answers1

0

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 
darius
  • 47
  • 3