Java Text File Write writeString(File outputFile, String text)

Here you can find the source of writeString(File outputFile, String text)

Description

write String

License

Open Source License

Declaration

public static void writeString(File outputFile, String text) throws IOException 

Method Source Code

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

import java.io.File;

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

public class Main {
    private static String DEFAULT_ENCODING = "utf-8";

    public static void writeString(File outputFile, String text, String encoding) throws IOException {
        writeBytes(outputFile, text.getBytes(encoding));
    }/*from w  w w. java2 s  .co  m*/

    public static void writeString(File outputFile, String text) throws IOException {
        writeString(outputFile, text, DEFAULT_ENCODING);
    }

    public static void writeBytes(File outputFile, byte[] bytes) throws IOException {
        outputFile.getParentFile().mkdirs();
        FileOutputStream outputStream = new FileOutputStream(outputFile);
        try {
            outputStream.write(bytes);
        } finally {
            outputStream.close();
        }
    }
}

Related

  1. writeString(File file, String s, int bufferSize, String encoding)
  2. writeString(File file, String str)
  3. writeString(File file, String str, String encoding)
  4. writeString(File file, String string)
  5. writeString(File file, String string)
  6. writeString(FileWriter fw, String s)
  7. writeString(final ObjectOutput objectOut, final String str)
  8. writeString(final ObjectOutput out, final String s)
  9. writeString(final String data, final int length, final byte[] destination, int offset)