Java Text File Write writeStringToFile(File f, String s)

Here you can find the source of writeStringToFile(File f, String s)

Description

write String To File

License

Open Source License

Declaration

public static boolean writeStringToFile(File f, String s) 

Method Source Code

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

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    public static final String charset = "UTF-8";

    public static boolean writeStringToFile(File f, String s) {
        OutputStream out = null;//w w w  .  j  a  va 2 s. c  o m
        try {
            out = new FileOutputStream(f);
            out.write(s.getBytes(charset));
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return false;
    }
}

Related

  1. writeStringTo(String _value, File _target)
  2. writeStringToFile(@Nonnull String string, @Nonnull final File file)
  3. writeStringToFile(CharSequence contents, String filename)
  4. writeStringToFile(File f, String content, boolean append)
  5. writeStringToFile(File f, String s)
  6. writeStringToFile(File f, String s)
  7. writeStringToFile(File file, String content)
  8. writeStringToFile(File file, String content)
  9. writeStringToFile(File file, String content)