Does anyone know how I can import a List into a text file?
Is there any difference if I try the same process in Groovy?

Recommended Answers

All 2 Replies

I couldn't speak to Groovy, but it's fairly straightforward to write a List to a file

try {
    List<String> someList = new ArrayList<String>();
    // obviously you would want to use a list with stuff in it
    BufferedWriter out = new BufferedWriter(
      new FileWriter("outfilename"));
    for (String item : someList){
        out.write(item);
        out.newLine();
    }
    out.flush();
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}

Thank you very much for the quick reply.
I will try it in Groovy and come back
to commend.It shouldn't be any different.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.