Java Text File Write writeStringToFile(File file, String text)

Here you can find the source of writeStringToFile(File file, String text)

Description

Writes a string into a file.

License

Open Source License

Parameter

Parameter Description
file text file
text text

Exception

Parameter Description
FileNotFoundException If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file

Declaration

public static void writeStringToFile(File file, String text) throws FileNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**/*from   ww  w  .j a  va2s. c o  m*/
     * Writes a string into a file.
     *
     * @param file text file
     * @param text text
     * @throws FileNotFoundException If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
     */
    public static void writeStringToFile(File file, String text) throws FileNotFoundException {
        PrintStream out = new PrintStream(file);
        out.print(text);
        out.close();
    }
}

Related

  1. writeStringToFile(File file, String str, boolean compress)
  2. writeStringToFile(File file, String string)
  3. writeStringToFile(File file, String string, String encoding)
  4. writeStringToFile(File file, String stringToWrite)
  5. writeStringToFile(File file, String text)
  6. writeStringToFile(File file, String text, boolean append)
  7. writeStringToFile(File file, String xml)
  8. writeStringToFile(File outf, String str)
  9. writeStringToFile(File outFile, String s)