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

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

Description

This writes a string into a given file.

License

Open Source License

Parameter

Parameter Description
fileName the file to write into
str the string to be written

Exception

Parameter Description
IOException if an I/O error occurs

Declaration

public static void writeString(String fileName, String str) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/*from   ww w . j  a  va  2  s  .c o m*/
     * This writes a string into a given file. It opens the file, rewrites everything in it and
     * closes it afterwards.
     *
     * @param fileName the file to write into
     * @param str the string to be written
     * @throws IOException if an I/O error occurs
     */
    public static void writeString(String fileName, String str) throws IOException {

        FileOutputStream os = new FileOutputStream(fileName);

        os.write(str.getBytes());
        os.close();
    }
}

Related

  1. writeString(String content, String path, String charset)
  2. writeString(String contents, File file)
  3. writeString(String contents, File file)
  4. writeString(String data, File file)
  5. writeString(String data, String file_path)
  6. writeString(String filePath, boolean append, String content, String encoding)
  7. writeString(String filePath, String content)
  8. writeString(String par0)
  9. writeString(String path, String key, String value)