Java Text File Write nio writeToFile(String filename, String fileContents)

Here you can find the source of writeToFile(String filename, String fileContents)

Description

write To File

License

Open Source License

Declaration

private static void writeToFile(String filename, String fileContents) 

Method Source Code


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

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;

public class Main {
    private static void writeToFile(String filename, String fileContents) {
        Writer writer = null;/*from   www  .  j a  va 2s  .  co  m*/

        try {
            writer = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.US_ASCII));
            writer.write(fileContents);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. writeToFile(File file, String content)
  2. writeToFile(File file, String str)
  3. writeToFile(final File file, final String data)
  4. writeToFile(String content, String fileName)
  5. writeToFile(String content, String fileName, boolean createFile)
  6. writeToFile(String filename, String... lines)
  7. writeTokenText(OutputStream theOs, String theStr)
  8. writeToTextFile(String fileName, String content)