String filename;
/* Set your fully qualified filename here */
String data = null;
/* Set your file contents into String here */
File file = new File(filename);
/* Create file, delete old file if necessary */
try {
if (file.exists()) {
file.delete();
}
file.createNewFile();
}
catch (IOException ioe) {
/* Your error handling goes here */
}
/* Open FileOutputStream */
FileOutputStream fileOut = new FileOutputStream(file);
/* Output contents of file */
try {
fileOut.write(data.getBytes());
}
catch (IOException ioe) {
/* Your error handling goes here */
}
finally {
fileOut.close();
}