Here you can find the source of writeString(final File file, final String str)
Parameter | Description |
---|---|
file | The file. |
str | The string to write. |
Parameter | Description |
---|---|
IOException | I/O Exception |
public static void writeString(final File file, final String str) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; public class Main { /** The UTF-8 charset. */ public static final Charset UTF8 = Charset.forName("UTF-8"); /**//from w ww . j a v a 2s . c om * Writes a string to the output stream. The output stream is flushed and * closed afterwards. * * @param out The output stream. * @param str The string to write. * @throws IOException I/O Exception */ public static void writeString(final OutputStream out, final String str) throws IOException { final Writer writer = new OutputStreamWriter(out, UTF8); writer.append(str); writer.flush(); writer.close(); } /** * Writes a string to a file. * * @param file The file. * @param str The string to write. * @throws IOException I/O Exception */ public static void writeString(final File file, final String str) throws IOException { writeString(new FileOutputStream(file), str); } }