@Testpublicvoidwrite_to_file_java()throwsIOException{Filefile=newFile(fileLocation);BufferedWriterout=newBufferedWriter(newFileWriter(file));out.write("writing to a file");out.close();}
Java 7 File I/O
@Testpublicvoidwrite_to_file_nio()throwsIOException{Pathpath=Paths.get(fileLocation);java.nio.file.Files.write(path,"writing to a file".getBytes(),StandardOpenOption.WRITE);}
Google Guava
@Testpublicvoidwrite_to_file_guava()throwsIOException{Filefile=newFile(fileLocation);Files.write("writing to a file",file,Charsets.UTF_8);}
Apache Commons
@Testpublicvoidwrite_to_file_apache()throwsIOException{Filefile=newFile(fileLocation);FileUtils.write(file,"writing to file");}