Java BufferedWriter create from OutputStream using system default encoding
import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; public class Main { public static void main(String[] args) throws Exception { OutputStream os = new FileOutputStream("Main.java"); Writer writer = new OutputStreamWriter(os, "US-ASCII"); try (BufferedWriter bw = new BufferedWriter(writer)) { bw.append("demo2s.com"); bw.newLine();/*from w w w .ja v a2s .c o m*/ bw.flush(); System.out.println("saved"); } catch (Exception e2) { e2.printStackTrace(); } } }