Here you can find the source of saveFile(String content, File f, String encoding)
Parameter | Description |
---|---|
content | which will be saved as it is saved in this String |
f | file to be saved. No warnings provided |
encoding | of output byte representation |
Parameter | Description |
---|---|
IOException | if save fails |
public static void saveFile(String content, File f, String encoding) throws IOException
//package com.java2s; // License as published by the Free Software Foundation; either import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; public class Main { /**/*ww w . jav a 2 s . com*/ * Method to save String as file in UTF-8 encoding. * * @param content which will be saved as it is saved in this String * @param f file to be saved. No warnings provided * @throws IOException if save fails */ public static void saveFile(String content, File f) throws IOException { saveFile(content, f, "utf-8"); } /** * Method to save String as file in specified encoding/. * * @param content which will be saved as it is saved in this String * @param f file to be saved. No warnings provided * @param encoding of output byte representation * @throws IOException if save fails */ public static void saveFile(String content, File f, String encoding) throws IOException { try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), encoding))) { output.write(content); output.flush(); } } }