1 22 package org.objectweb.petals.util; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.OutputStream ; 28 29 37 public final class FileUtil { 38 39 43 private static final int DEFAULT_BUFFER_SIZE = 4096; 44 45 48 private FileUtil() { 49 super(); 50 } 51 52 59 public static void copyInputStream(InputStream in, OutputStream out) 60 throws IOException { 61 byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; 62 int len; 63 while ((len = in.read(buffer)) >= 0) { 64 out.write(buffer, 0, len); 65 } 66 in.close(); 67 out.close(); 68 } 69 70 public static boolean removeDirectory(File dir) { 71 72 boolean completeRemoval = true; 73 74 if (!dir.isDirectory() && !dir.exists()) { 75 return false; 76 } 77 78 for (File aFile : dir.listFiles()) { 80 81 if (aFile.isDirectory()) { 82 completeRemoval = removeDirectory(aFile); 83 } else { 84 completeRemoval = aFile.delete(); 85 } 86 } 87 88 if (completeRemoval) { 89 completeRemoval = dir.delete(); 91 } else { 92 System.out.println("Directory not deleted because not empty :" 94 + dir.getAbsolutePath()); 95 } 96 97 return completeRemoval; 98 } 99 100 } 101 | Popular Tags |