Java Text File Write writeStringToFile(String s, File f)

Here you can find the source of writeStringToFile(String s, File f)

Description

Writes a string to a file replacing the entire contents

License

Apache License

Parameter

Parameter Description
s The string to write
f The file to write to

Exception

Parameter Description

Declaration

public static void writeStringToFile(String s, File f)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**//w  ww . j  av a  2s .  c om
     * Writes a string to a file replacing the entire contents
     *
     * @param s The string to write
     * @param f The file to write to
     * @throws java.io.IOException
     */
    public static void writeStringToFile(String s, File f)
            throws IOException {
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(f));
            bw.write(s);
        } finally {
            if (null != bw) {
                bw.close();
            }
        }
    }
}

Related

  1. writeStringToFile(String modifiedLine, String filePath)
  2. writeStringToFile(String path, String content)
  3. writeStringToFile(String path, String content)
  4. writeStringToFile(String path, String content)
  5. writeStringToFile(String path, String contents)
  6. writeStringToFile(String s, File f)
  7. writeStringToFile(String s, File f)
  8. writeStringToFile(String s, File file)
  9. writeStringToFile(String s, String filename)