Here you can find the source of writeToFile(Path path, String content)
public static void writeToFile(Path path, String content) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.file.Path; public class Main { public static void writeToFile(Path path, String content) throws FileNotFoundException, IOException { Writer writer = null;//from w w w . j a v a 2s.co m try { BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(path.toString())); writer = new OutputStreamWriter(outputStream); writer.write(content); } finally { if (writer != null) writer.close(); } } }