Here you can find the source of saveFile(final File file, final String contents, final String encoding)
Parameter | Description |
---|---|
file | The location/name of the file to be saved. |
contents | The data that is to be written to the file. |
Parameter | Description |
---|---|
IOException | an exception |
public static void saveFile(final File file, final String contents, final String encoding) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**/*from w w w . j av a2 s.c o m*/ * Save the data, represented as a String to a file * * @param file The location/name of the file to be saved. * @param contents The data that is to be written to the file. * @throws IOException */ public static void saveFile(final File file, final String contents, final String encoding) throws IOException { saveFile(file, contents.getBytes(encoding)); } /** * Save the data, represented as a byte array to a file * * @param file The location/name of the file to be saved. * @param fileContents The data that is to be written to the file. * @throws IOException */ public static void saveFile(final File file, byte[] fileContents) throws IOException { if (file.isDirectory()) { throw new IOException("Unable to save file contents as a directory."); } final FileOutputStream fos = new FileOutputStream(file); fos.write(fileContents); fos.flush(); fos.close(); } }