Java Text File Write writeStringToFile(File pFile, String pString)

Here you can find the source of writeStringToFile(File pFile, String pString)

Description

Writes the content of a string to a file.

License

Open Source License

Parameter

Parameter Description
pFile file
pString string

Exception

Parameter Description
IOException if file cannot be writen

Declaration

public static final void writeStringToFile(File pFile, String pString) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

import java.io.PrintWriter;

public class Main {
    /**/*from   w  w w. j  a  v a2 s . c  o  m*/
     * Writes the content of a string to a file.
     * 
     * From:
     * https://stackoverflow.com/questions/1053467/how-do-i-save-a-string-to-a-text-file-using-java
     * 
     * @param pFile
     *          file
     * @param pString
     *          string
     * @throws IOException
     *           if file cannot be writen
     */
    public static final void writeStringToFile(File pFile, String pString) throws IOException {

        try (PrintWriter out = new PrintWriter(pFile)) {
            out.print(pString);
        }
    }
}

Related

  1. writeStringToFile(File file, String text, boolean append)
  2. writeStringToFile(File file, String xml)
  3. writeStringToFile(File outf, String str)
  4. writeStringToFile(File outFile, String s)
  5. writeStringToFile(File p_out, String p_str)
  6. writeStringToFile(final File file, final String data)
  7. writeStringToFile(final File file, final String data)
  8. writeStringToFile(final String path, final String output)
  9. writeStringToFile(final String string, final File file)