Пример #1
0
 /**
  * Takes an input dir and returns the du on that local directory. Very basic implementation.
  *
  * @param dir The input dir to get the disk space of this local dir
  * @return The total disk space of the input local directory
  */
 public static long getDU(File dir) {
   long size = 0;
   if (!dir.exists()) return 0;
   if (!dir.isDirectory()) {
     return dir.length();
   } else {
     File[] allFiles = dir.listFiles();
     if (allFiles != null) {
       for (int i = 0; i < allFiles.length; i++) {
         boolean isSymLink;
         try {
           isSymLink = org.apache.commons.io.FileUtils.isSymlink(allFiles[i]);
         } catch (IOException ioe) {
           isSymLink = true;
         }
         if (!isSymLink) {
           size += getDU(allFiles[i]);
         }
       }
     }
     return size;
   }
 }
Пример #2
0
 /**
  * 判断文件是否为链接文件
  *
  * @param file
  * @return
  * @throws IOException
  */
 public static boolean isLink(File file) throws IOException {
   return FileUtils.isSymlink(file);
 }