-
write to txt file
Hello guys. I have create two txt files and I wan to parse things there.
Code:
FileWriter outFile1 = new FileWriter("newFaces.txt", true);
FileWriter outFile2 = new FileWriter("newVertices.txt", true);
PrintWriter out1 = new PrintWriter(outFile1);
PrintWriter out2 = new PrintWriter(outFile2);
and I want to parse some variables inside a for loop but i want iteration to add new lines in the txt(to append lines).
Code:
for (int i=0;i<4; i++){ //for example
out2.append(newvertex1+" "+newvertex2+" "+ newvertex3);
out2.println();
out2.close();
out1.append(aString+" "+aString1+" "+ aString3);
out1.println();
out1.append(aString+" "+aString1+" "+ aString4);
out1.println();
out1.append(aString+" "+aString2+" "+ aString3);
out1.println();
out1.append(aString+" "+aString2+" "+ aString4);
out1.println();
out1.close();
}
This work like a charm only for the first iteration. In the end of the loop i ve onlyl the data of the first iteration. Have you any idea upon this matter? What i m doing wrong?
-
Why exactly are you closing your PrintWriter's in your loop? Close your PrintWriter's when the loop is done; that's the reason why only your first iteration is being written.
-
Hmm you are so true!!! Thank you.