Here you can find the source of saveToFile(File file, String string)
Parameter | Description |
---|---|
file | The file to save string to. |
string | The string. |
Parameter | Description |
---|---|
IOException | Signals that an I/O exception has occurred. |
public static void saveToFile(File file, String string) throws IOException
//package com.java2s; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; public class Main { /**/*from w w w .j a v a 2 s . com*/ * Saves string to file. * * @param file * The file to save string to. * @param string * The string. * @throws IOException * Signals that an I/O exception has occurred. */ public static void saveToFile(File file, String string) throws IOException { try (BufferedWriter out = new BufferedWriter(new FileWriter(file))) { out.write(string); } } /** * Saves bytes to file. * * @param file * The file to save bytes to. * @param data * The data to save. * @throws IOException * Signals that an I/O exception has occurred. */ public static void saveToFile(File file, byte[] data) throws IOException { try (FileOutputStream out = new FileOutputStream(file)) { out.write(data); } } }