This is the code I currently have:
public class FileStatus extends Status{
FileWriter writer;
public FileStatus(){
try {
writer = new FileWriter("status.txt",true);
} catch (IOException e) {
e.printStackTrace();
}
}
public void writeToFile(){
String file_text= pedStatusText + " " + gatesStatus + " " + DrawBridgeStatusText;
try {
writer.write(file_text);
writer.flush();
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
My code works fine, but when it calls the writeToFile method for the second time I get the following:
java.io.IOException: Stream closed
Even though the file is written to the second time, it always throws the above error whenever I give a call to writeToFile(). Can anyone tell me how to resolve this error?