Java UTF File Write writeToFile(String outputFilePath, String generated)

Here you can find the source of writeToFile(String outputFilePath, String generated)

Description

write To File

License

Open Source License

Declaration

public static void writeToFile(String outputFilePath, String generated) 

Method Source Code


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

import java.io.*;
import java.nio.charset.Charset;

public class Main {
    public static void writeToFile(String outputFilePath, String generated) {
        File outputFile = new File(outputFilePath);

        //create dirs if not exist
        if (outputFile.getParent() != null && !new File(outputFile.getParent()).exists()) {
            File parent = new File(outputFile.getParent());
            parent.mkdirs();//from  w w  w .j av  a 2s .c om
        }
        //write
        try (PrintWriter output = new PrintWriter(outputFile, Charset.forName("UTF-8").name())) {
            output.print(generated);
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            System.out.println("Error while writing to file :" + e);
            throw new RuntimeException(e);
        }
    }
}

Related

  1. writeFile(String fileName, ArrayList data, String outputFolder)
  2. writeFileUTF(String nom)
  3. writeStringAsUTFByteArrayToDataOutput(final DataOutput out, final String str)
  4. writeToFile(File outputFile, String content)
  5. writeToFile(String outputFile, String contents)
  6. writeUTF8(DataOutput buf, String value)
  7. writeUTF8(final String filePath, final String content)
  8. writeUTF8(OutputStream out, String str)
  9. writeUtf8String(final DataOutputStream out, final String str)