This class file
can be used to write a string to a new file or to append an existing
file, providing the string and the file name as arguments.
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class WriteFile
{
public void FileWrite(String fileName, String fileContent) /*
* Method to
* write content
* to a file
*/
{
try {
File file = new File(fileName);
FileWriter fstream = new FileWriter(file.getName(), true); /*
* Will
* write
* to a
* new
* to a
* new
* file
* or
* append
* to an
* existing
* one
*/
BufferedWriter bw = new BufferedWriter(fstream);
bw.write(fileContent);
bw.close();
} catch (Exception e) {
System.out.println("Exception caught: " + e.getMessage());
e.printStackTrace();
}
}
}