Here you can find the source of writeFile(final File file, final String contents)
protected static void writeFile(final File file, final String contents) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { protected static void writeFile(final File file, final String contents) throws IOException { final File result = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".new"); final FileOutputStream out = new FileOutputStream(result); out.write(contents.getBytes());//from ww w . j a v a 2s . c o m out.close(); result.renameTo(file); } }