Show FileHelper.java syntax highlighted
package net.time4tea.webstats.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
/**
* Originally richja 25-Jun-2007
*/
public class FileHelper {
public static boolean recursivelyDelete(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (String child : children) {
boolean success = recursivelyDelete(new File(dir, child));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
public static void copyFile(File in, File out) throws Exception {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
public static void copyTo(InputStream in, File out) throws Exception {
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while ((i = in.read(buf)) != -1) {
fos.write(buf, 0, i);
}
in.close();
fos.close();
}
}
See more files for this project here