Here you can find the source of getWriter(String path, Charset encoding)
Parameter | Description |
---|---|
path | the location where the file should be persisted |
encoding | the character set used for writing the file |
public static BufferedWriter getWriter(String path, Charset encoding) throws FileNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; public class Main { /**//from ww w. j a va 2s . c o m * Returns a writer that uses the UTF8 encoding. * * @param path the location where the file should be persisted * @return a reader that uses the UTF8 encoding */ public static BufferedWriter getWriter(String path) throws FileNotFoundException { return getWriter(path, StandardCharsets.UTF_8); } /** * Returns a writer that uses the given encoding. * * @param path the location where the file should be persisted * @param encoding the character set used for writing the file * @return a writer that uses the given encoding */ public static BufferedWriter getWriter(String path, Charset encoding) throws FileNotFoundException { return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path)), encoding)); } }