I create file then I test and write to it first time everything is good but when I rerun the program it find the file so it should flush its content then do what ever I told it to do but there I get my problem can't erease and can't write:
The calling :
Code:
public FileWriter createFile(String name)
{
if(!FileOrDirectoryExists(name))
{
//erase the content of the file
try{
fstream = new FileWriter(name);
}
catch (Exception e) {
System.err.println("Error: can't create");
}
}
//erase the content of the file
else
{
try{
this.fstream.flush();
this.fstream.close();
}
catch (Exception e) {
System.err.println("Error: can't erease");
}
}
return fstream;
}
/**
* This file writes the text into the file.
*
* @param text
*/
public void write(String text)
{
try{
BufferedWriter file = new BufferedWriter(fstream);
file.write(text);
file.close();
}
catch (Exception e) {
System.err.println("Error: can't write");
}
}
Code:
FileDirectoryFactory file = new FileDirectoryFactory();
file.createFile("orm.xml");
file.write("hello world");
Comment