I have trouble with write txt file from class FileWrite in my java project , if the PRINT() method were in VehicleCollection class , and called in main class - don\'t have p
Since you are already using Java 7, why not use the try-with-resources construct to avoid having to do things like close streams:
try( File file = new File("krasiWrite.txt");
Writer writer = new BufferedWriter(new java.io.FileWriter(file)); )
{
String text = getArrList().toString();
writer.write(text);
writer.flush(); // this lines takes whatever is stored in the BufferedWriter's internal buffer
// and writes it to the stream
}
catch(IOException ioe) {
// ... handle exception
}
// now all resources are closed.