Hi everybody !
I want to create a File then write to it so here is what I use:
the files are created but can't be written using my method...??
here is how I use them:
I want to create a File then write to it so here is what I use:
Code:
public File creatFile(String name)
{
File file = new File(name);
try {
file.createNewFile();
} catch (Exception e) {
System.out.println("file" + name + "not created");
}
return file;
}
public void writeToFile(File file, String text)
{
try {
fstream = new FileWriter(file, false);
BufferedWriter bufferedFile = new BufferedWriter(fstream);
bufferedFile.write(text);
} catch (Exception e) {
System.err.println("can not write to" + file.getName());
}
}
here is how I use them:
Code:
FileFactory f = new FileFactory();
for(int i = 0; i < 3; i++)
{
File file = f.creatFile("text" + i + ".txt");
f.writeToFile(file, "Hello World!");
}
Comment