Java Text File Write writeStringToFile(File p_out, String p_str)

Here you can find the source of writeStringToFile(File p_out, String p_str)

Description

Writes a string to a file

License

Open Source License

Parameter

Parameter Description
p_out The output file
p_str The string to write

Return

The success status

Declaration

public static boolean writeStringToFile(File p_out, String p_str) 

Method Source Code

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

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {
    /**// ww w  . ja va  2s .  c  o m
     * Writes a string to a file
     * @param p_out The output file
     * @param p_str The string to write
     * @return The success status
     */
    public static boolean writeStringToFile(File p_out, String p_str) {
        try {
            OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(p_out));
            osw.write(p_str + System.lineSeparator());
            osw.flush();
            osw.close();
        } catch (FileNotFoundException e) {
            return false;
        } catch (IOException e) {
            return false;
        }
        return true;
    }
}

Related

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