Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package ch.cern.mig.utils;
 
 import java.io.File;

Author(s):
Massimo Paladin - massimo.paladin@gmail.com
Copyright (C) CERN 2012-2013
public class FileUtils {
    public static void writeToFile(File pathbyte[] datathrows IOException {
        FileOutputStream newFileStream = new FileOutputStream(path);
        BufferedOutputStream newFileOut = new BufferedOutputStream(
                newFileStream);
        newFileOut.write(data);
        newFileOut.close();
        newFileStream.close();
    }
    public static void writeToFile(String pathbyte[] datathrows IOException {
        writeToFile(new File(path), data);
    }
    public static void writeToFile(File pathString datathrows IOException {
        FileWriter newFileStream = new FileWriter(path);
        BufferedWriter newFileOut = new BufferedWriter(newFileStream);
        newFileOut.write(data);
        newFileOut.close();
        newFileStream.close();
    }
    public static void writeToFile(String pathString datathrows IOException {
        writeToFile(new File(path), data);
    }
    public static String readToString(String path) {
        return readToString(new File(path));
    }
    public static String readToString(File tmp) {
        String content = "";
        try {
            content = new Scanner(tmp"UTF-8").useDelimiter("\\A").next();
        } catch (FileNotFoundException e) {
            return null;
        }
        return content;
    }
    public static byte[] readToByteArray(String path) {
        return readToByteArray(new File(path));
    }
    public static byte[] readToByteArray(File file) {
        byte content[] = null;
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            content = new byte[(intfile.length()];
            fileInputStream.read(content);
        } catch (FileNotFoundException e) {
            return null;
        } catch (IOException ioe) {
            return null;
        }
        return content;
    }
    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.lengthi++) {
                boolean success = deleteDir(new File(dirchildren[i]));
                if (!success) {
                    return false;
                }
            }
        }
        return dir.delete();
    }
New to GrepCode? Check out our FAQ X