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

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

Description

write String To File

License

Open Source License

Declaration

public static void writeStringToFile(String s, File file) 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;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static void writeStringToFile(String s, File file) throws IOException {
        OutputStream out = null;//from  w w  w .  j av  a2 s . c  o m
        try {
            out = new FileOutputStream(file);
            out.write(s.getBytes());
        } finally {
            forceClosed(out);
        }
    }

    public static void forceClosed(InputStream stream) {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            }
        }
    }

    public static void forceClosed(OutputStream stream) {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            }
        }
    }
}

Related

  1. writeStringToFile(String path, String content)
  2. writeStringToFile(String path, String contents)
  3. writeStringToFile(String s, File f)
  4. writeStringToFile(String s, File f)
  5. writeStringToFile(String s, File f)
  6. writeStringToFile(String s, String filename)
  7. writeStringToFile(String s, String filePathname)
  8. writeStringToFile(String sdat, File f)
  9. writeStringToFile(String str, File file)