I've been trying this for the last half an hour, but all I can come up with is the following:
for (int y = 0; y < colectieTotala.size(); y++)
for (int k = 0; k < colectieTotala.get(y).size(); k++)
{
try(BufferedWriter output = new BufferedWriter(new FileWriter("D:\\Programe\\NetBeans\\Proiecte NetBeans\\[PA]Tema3Ex1\\Colectie.txt", true)))
{
output.write(colectieTotala.get(y).get(k)); output.newLine();
}
}
This is the structure of Colectie.txt: http://postimg.org/image/656f1mow5/
The problem is that it wrote the current String only on the first line of the file Colectie.txt, replacing the String introduced earlier, so that at the end of the program all I have in the Colectie.txt is this: /
I think it's just something easy, but can't figure it out what...
EDIT:
OK, I did edit my code, and this is how it looks now:
BufferedWriter output = new BufferedWriter(new FileWriter("D:\\Programe\\NetBeans\\Proiecte NetBeans\\[PA]Tema3Ex1\\Colectie.txt"));
for (int y = 0; y < colectieTotala.size(); y++)
for (int k = 0; k < colectieTotala.get(y).size(); k++)
{
System.out.println("Element curent -> " + colectieTotala.get(y).get(k));
try
{
output.write(colectieTotala.get(y).get(k));
output.newLine();
}
catch (IOException e)
{
System.err.println(e);
}
}
The problem now is that Colectie.txt it's empty after this gets executed. Where's the mistake now ?