Java Text File Write writeStringToFile(String content, File outputfile)

Here you can find the source of writeStringToFile(String content, File outputfile)

Description

Write a string to a file

License

Open Source License

Parameter

Parameter Description
content The string to write out
outputfile The file to which the string will be written

Declaration

public static void writeStringToFile(String content, File outputfile) 

Method Source Code

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

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
    /**/*from w ww .j  a v a  2  s.c  o  m*/
     * Write a string to a file
     *  @param content The string to write out
     *  @param outputfile The file to which the string will be written
     */
    public static void writeStringToFile(String content, File outputfile) {
        if (content != null && !content.equals("") && outputfile != null) {
            try {
                PrintWriter pwriter = new PrintWriter(new FileWriter(
                        outputfile));
                pwriter.print(content);
                pwriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. writeStringToFile(final String path, final String output)
  2. writeStringToFile(final String string, final File file)
  3. writeStringToFile(final String text, final File filePath)
  4. writeStringToFile(String content, File file)
  5. writeStringToFile(String content, File file)
  6. writeStringToFile(String content, File targetFile)
  7. writeStringToFile(String content, String encoding, String fileName)
  8. writeStringToFile(String content, String filename)
  9. writeStringToFile(String content, String filename)