Java Text File Write writeStringToFile(CharSequence contents, String filename)

Here you can find the source of writeStringToFile(CharSequence contents, String filename)

Description

writes string contents to file file

License

Open Source License

Parameter

Parameter Description
contents a parameter
filename a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void writeStringToFile(CharSequence contents, String filename) throws IOException 

Method Source Code


//package com.java2s;

import java.io.File;

import java.io.IOException;
import java.io.PrintStream;

public class Main {
    /**//  w  ww  .j  av a2s  . c  o m
     * writes string contents to file file
     * 
     * @param contents
     * @param file
     * 
     * @throws IOException
     */
    public static void writeStringToFile(CharSequence contents, File file) throws IOException {
        PrintStream ps = null;

        try {
            ps = new PrintStream(file);

            ps.print(contents);

            ps.close();
        } finally {
            if (ps != null)
                //try { ps.close(); } catch ( IOException e ) {}
                ps.close();
        }
    }

    /**
     * writes string contents to file file
     * 
     * @param contents
     * @param filename
     * 
     * @throws IOException
     */
    public static void writeStringToFile(CharSequence contents, String filename) throws IOException {
        writeStringToFile(contents, new File(filename));
    }
}

Related

  1. writeStringListToFile(File file, ArrayList lines)
  2. writeStringListToFile(File file, List lines)
  3. writeStringTo(File outFile, String data)
  4. writeStringTo(String _value, File _target)
  5. writeStringToFile(@Nonnull String string, @Nonnull final File file)
  6. writeStringToFile(File f, String content, boolean append)
  7. writeStringToFile(File f, String s)
  8. writeStringToFile(File f, String s)
  9. writeStringToFile(File f, String s)