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

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

Description

write String To File

License

Open Source License

Declaration

public static boolean writeStringToFile(String sdat, File f) 

Method Source Code


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

import java.io.*;

import java.util.zip.GZIPOutputStream;

public class Main {
    public static boolean writeStringToFile(String sdat, File f) {
        String fnm = f.getName();
        boolean ok = false;
        if (f != null) {
            boolean dogz = (fnm.endsWith(".gz"));
            try {
                OutputStream fos = new FileOutputStream(f);
                if (dogz) {
                    fos = new GZIPOutputStream(fos);
                }//from www. j a  v a  2s .  c  o  m
                OutputStreamWriter osw = new OutputStreamWriter(fos);

                osw.write(sdat, 0, sdat.length());
                osw.close();
                ok = true;

            } catch (IOException ex) {
                throw new RuntimeException("File write error, when writing " + fnm);
            }
        }
        return ok;
    }
}

Related

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