Java Text File Write writeString(File file, String data)

Here you can find the source of writeString(File file, String data)

Description

write String

License

Open Source License

Parameter

Parameter Description
data the data to write in the file

Declaration

public static void writeString(File file, String data) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**//from w w  w  . j a v  a  2s . c o  m
     *
     * @param dir  directory to put the file in
     * @param name name of new file
     * @param data the data to write in the file
     */
    public static void writeString(File dir, String name, String data) throws IOException {
        writeString(new File(dir, name), data);
    }

    /**
     *
     * @param data the data to write in the file
     */
    public static void writeString(File file, String data) throws IOException {
        PrintWriter out = null;
        try {
            out = new PrintWriter(new FileOutputStream(file));
            out.print(data);
        } finally {
            //       try {
            if (out != null)
                out.close();
            //        } catch (IOException e) {}
        }
    }
}

Related

  1. writeString(File file, String content, boolean append)
  2. writeString(File file, String s, int bufferSize, String encoding)
  3. writeString(File file, String str)
  4. writeString(File file, String str, String encoding)
  5. writeString(File file, String string)