Here you can find the source of saveInFile(String filename, String content, String charsetName)
Parameter | Description |
---|---|
filename | The file name. |
content | The content of the file. |
charsetName | The charset of the string. |
Parameter | Description |
---|---|
Exception | an exception |
public static File saveInFile(String filename, String content, String charsetName) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; public class Main { /**/*w ww .j a va 2 s. c o m*/ * Save in a file the content of a string. It's very useful for debug. * * @param filename The file name. * @param content The content of the file. * @param charsetName The charset of the string. * @return New file instance * @throws Exception */ public static File saveInFile(String filename, String content, String charsetName) throws Exception { InputStream is = new ByteArrayInputStream(content.getBytes(charsetName)); byte[] b = new byte[2048]; int length; OutputStream os = new FileOutputStream(filename); while ((length = is.read(b)) != -1) { os.write(b, 0, length); } os.close(); return new File(filename); } /** * Save in a file the content of a string. It's very useful for debug. * * @param filename The file name. * @param content The content of the file. * @return New file instance. * @throws Exception */ public static File saveInFile(String filename, String content) throws Exception { return saveInFile(filename, content, "ISO-8859-1"); } }