Java Text File Write writeStringToFile(String contents, File outputFile)

Here you can find the source of writeStringToFile(String contents, File outputFile)

Description

write String To File

License

Apache License

Declaration

public static void writeStringToFile(String contents, File outputFile) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

import java.io.OutputStreamWriter;
import java.io.Writer;

public class Main {
    public static void writeStringToFile(String contents, File outputFile) {

        Writer os = null;/*from  ww  w  . ja  v  a2 s .  c om*/
        try {

            FileOutputStream fos = new FileOutputStream(outputFile);
            os = new OutputStreamWriter(fos, "UTF-8");
            os.write(contents);

        } catch (IOException e) {
            throw new RuntimeException(e.getMessage());
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
        }

    }
}

Related

  1. writeStringToFile(String content, String fileName, boolean append)
  2. writeStringToFile(String content, String filePath)
  3. writeStringToFile(String content, String path)
  4. writeStringtoFile(String content, String path)
  5. writeStringToFile(String contents, File outfile)
  6. writeStringToFile(String contents, String path)
  7. writeStringToFile(String contents, String path, String encoding)
  8. writeStringToFile(String data, String filename, boolean append)
  9. writeStringToFile(String data, String filepath)