Traversing the directory to delete, achieve size and depth

zhaozj2021-02-16  78

import java.io *;. import java.util *;. public class ManageContent {private int dir_deep = 0; private int dir_size = 0; private int sourcepath_deep; // input path depth relative to the root private Hashtable ht = new Hashtable (); // Save all subdirectories under the input path, and its depth keys = (string) DirPath, Values ​​= (Integer) DirdeEp Public Synchronized int GetSize (String Dir_path) thrownotfoundexception {file dir = new File (Dir_Path); if (! Dir.exists ()) {throw new filenotfoundexception ();} if (! Dir.Indirectory ()) {DIR_SIZE = (int) Dir.length ();} else {file [] Fe = dir.listfiles (); for (int i = 0; i

public synchronized void deleteFiles (String dir_path) throws FileNotFoundException {File file = new File (dir_path); if {throw new FileNotFoundException () (file.exists ()!);} if (file.isDirectory ()) {File [] fe = file.listfiles (); for (int i = 0; i

Private void alldeep (file file) {file [] fe = file.listfiles (); for (int i = 0; i max) max = values.intValue ();} returnes Max;} private int count (string str) {string regex = "/"; if ("file.seProperty). Equals (" // ")) // WINDOWS and UNIX path split same Regex = ""; Return Str.Split (regex) .length;}} In the depth of the directory, I obtained the depth of all the subdirectory relative to the root directory by split string, and then subtract the input directory The depth of the input directory is obtained with respect to the depth of the root directory. I feel that this method is not effective, and which friend has a better way, I hope I will enlighten me.

转载请注明原文地址:https://www.9cbs.com/read-13552.html

New Post(0)