Java Text File Write writeString(String path, String str)

Here you can find the source of writeString(String path, String str)

Description

write String

License

Open Source License

Declaration

public static void writeString(String path, String str) 

Method Source Code


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

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Main {
    public static void writeString(String path, String str) {
        BufferedWriter out = null;
        try {//from   w  ww  .j av a  2s. c  o  m
            File f = new File(path);
            File parent = f.getParentFile();
            if (!parent.exists())
                parent.mkdirs();
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
            out.write(str);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (Exception ex) {
                }
            }
        }
    }
}

Related

  1. writeString(String fileName, String str)
  2. writeString(String filePath, boolean append, String content, String encoding)
  3. writeString(String filePath, String content)
  4. writeString(String par0)
  5. writeString(String path, String key, String value)
  6. writeString(String path, String str, boolean append)
  7. writeString(String s, File output, String encoding)
  8. writeString(String string, ObjectOutput out)
  9. writeString(String value)