B
B
bychok3002016-11-20 18:15:50
Java
bychok300, 2016-11-20 18:15:50

Writing a collection to a file, how to do it right?

there is a parser

try{
        	//конектимся
            Document doc = Jsoup.connect("http://" +parserParam).get();
            //добавляем в список из элементов все что лежит между тегами <html> </html>
            List<Element> elements = doc.select("html");
    		
            //выводим на клиента все что спарсилось	
            out.print(elements);  
        }
        //перехватываем исключение если че
        catch(Exception e){
        	e.printStackTrace();
        	out.print("ERROR, possible somthing wrong with your query");
        }
        //закрываем поток вывода
    out.close();

The question is, how can I write what I was able to write to a file? I have already tried both FileInputStream and FileWriter at the moment when I call the .write() method Eclipse underlines it with an error

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2016-11-20
@bychok300

In what format?
The simplest is to convert your List to json using any of the 100500 libraries (I like Gson for example), and write to the file as a string.

I
Ilya Los, 2018-04-17
@Jarik01

Can you share how this story ends?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question