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

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

Description

write String

License

Open Source License

Declaration

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

Method Source Code


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

import java.io.*;

public class Main {

    public static void writeString(File file, String string) throws IOException {
        writeString(file, string, "UTF-8");
    }/*from   w ww  .ja  va  2 s  .  c o m*/

    public static void writeString(File file, String string, String encode) {
        OutputStreamWriter write = null;
        BufferedWriter writer = null;
        try {
            write = new OutputStreamWriter(new FileOutputStream(file), encode);
            writer = new BufferedWriter(write);
            writer.write(string);
            writer.close();
        } catch (Exception e) {
            throw new RuntimeException("writeString to file " + file.getPath(), e);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                }
            }
            if (write != null) {
                try {
                    write.close();
                } catch (IOException e) {
                }
            }
        }
    }
}

Related

  1. writeString(File file, String content, boolean append)
  2. writeString(File file, String data)
  3. writeString(File file, String s, int bufferSize, String encoding)
  4. writeString(File file, String str)
  5. writeString(File file, String str, String encoding)
  6. writeString(File file, String string)
  7. writeString(File outputFile, String text)
  8. writeString(FileWriter fw, String s)
  9. writeString(final ObjectOutput objectOut, final String str)