Here you can find the source of writeString(String s, File output, String encoding)
Parameter | Description |
---|---|
s | string |
output | output file |
encoding | file encoding |
public static void writeString(String s, File output, String encoding) throws IOException
//package com.java2s; //License from project: BSD License import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringReader; public class Main { /**// w ww.j a v a2 s .c om * Writes a string to a file, using the given encoding. An existing file is * overwritten. * * @param s string * @param output output file * @param encoding file encoding */ public static void writeString(String s, File output, String encoding) throws IOException { BufferedReader buffer = new BufferedReader(new StringReader(s)); FileOutputStream fos = new FileOutputStream(output); PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, encoding)); for (String nextLine; (nextLine = buffer.readLine()) != null;) writer.println(nextLine); writer.close(); buffer.close(); } }