Traversing the directory to delete, achieve size and depth

xiaoxiao2021-03-06  35

Directory traversal realize delete, get the size and depth Source: 9CBS Author: shuqianlz following class implements the operation of the directory, including the deletion, taking the size and depth.

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

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

New Post(0)