Having this kind of subdirectories:
C:\test\foo\a.dat (100kb)
C:\test\foo\b.dat (200kb)
C:\test\foo\another_dir\jim.dat (500kb)
C:\test\bar\ball.jpg (5kb)
C:\test\bar\sam\sam1.jpg (100kb)
C:\test\bar\sam\sam2.jpg (300kb)
C:\test\somefile.dat (700kb)
I want to get size of all subdirectories, but only show the top directory, Running the command java DU c:\test should produce the following output:
DIR C:\TEST\FOO 800KB
FILE C:\TEST\SOMEFILE.DAT 700KB
DIR C:\TEST\BAR 405KB
any help will be great, my code so far is close but not getting the expected output ? :/
import java.io.File;
public class DU {
public static void main(String[] args) {
File file = new File(args[0]);
if (file.isDirectory()) {
File[] filesNames = file.listFiles();
for (File temp : filesNames) {
if (temp.isDirectory()) {
File dirs = new File(temp.getPath());
getDirSize(dirs);
} else {
System.out.println("FILE - " + temp.getPath() + " "
+ friendlyFileSize(temp.length()));
}
}
} else {
System.out.println("THIS IS NOT A FILE LOCATION!");
}
}
private static long getDirSize(File dirs) {
long size = 0;
for (File file : dirs.listFiles()) {
if (file.isFile())
size += file.length();
else
size += getDirSize(file);
}
System.out.println("DIR - " + dirs+" "+ friendlyFileSize(size));
return size;
}
public static String friendlyFileSize(long size) {
String unit = "bytes";
if (size > 1024) {
size = size / 1024;
unit = "kb";
}
if (size > 1024) {
size = size / 1024;
unit = "mb";
}
if (size > 1024) {
size = size / 1024;
unit = "gb";
}
return " (" + size + ")" + unit;
}
}
This code get the output of all subdirectories instead showing a total of all of them and printing just top directory ??? Many thx for any help :D
FILE - c:\test\baba.pdf (4)mb
FILE - c:\test\babdb.txt (67)kb
DIR - c:\test\one\oneone (67)kb
DIR - c:\test\one (814)kb
DIR - c:\test\two\twotwo (322)kb
DIR - c:\test\two (368)kb
Your recquirement is that input a folder then show the sizes of all files(file including folder) of the folder.
We define the size of a folder is the sum of the size of files in the folder(including sub-folder).
So, the process of the source code is below:
(1) list-up all files of the folder as input.
(2) calculate file-size of listing in (1).
(3) show file-type(FILE OR DIR), the paths of files listing in (1), and file-size calculated in (2).
the source code of (1) and (3) is below:
public static void showFileSizes(File dir) {
File[] files = dir.listFiles(); // (1)
long[] fileSizes = new long[files.length];
for(int i = 0; i < files.length; i++) {
fileSizes[i] = calculateFileSize(file[i]);//invoke the method corresponding to (2).
boolean isDirectory = files[i].isDirectory();
System.out.println(((isDirectory)?"DIR":"FILE") + " - " + files[i].getAbsolutePath() + friendlyFileSize(fileSizes[i]));// as (3)
}
}
the source code of (2) is below:
public static long calculateFileSize(File file) {
long fileSize = 0L;
if(file.isDirectory()) {
File[] children = file.listFiles();
for(File child : children) {
fileSize += calculateFileSize(child);
}
}
else {
fileSize = file.length();
}
return fileSize;
}
The only thing you have to do is invoke showFileSizes method.
It is quite easy by using Java 7 new File I/O NIO.2 framework mostly by using Files.walkFileTree(Path, Set, int, FileVisitor) method.
import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.EnumSet;
import java.util.concurrent.atomic.AtomicLong;
public class Main {
private static class PrintFiles extends SimpleFileVisitor<Path> {
#Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
if (attr.isDirectory()) {
try {
System.out.format("Directory: %s, size: %d bytes\n", file, getDirSize(file));
} catch (IOException e) {
e.printStackTrace();
}
} else if (attr.isRegularFile()) {
System.out.format("Regular file: %s, size %d bytes\n", file, attr.size());
}
return FileVisitResult.CONTINUE;
}
#Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
System.err.println(exc);
return FileVisitResult.CONTINUE;
}
/**
* Walks through directory path and sums up all files' sizes.
*
* #param dirPath Path to directory.
* #return Total size of all files included in dirPath.
* #throws IOException
*/
private long getDirSize(Path dirPath) throws IOException {
final AtomicLong size = new AtomicLong(0L);
Files.walkFileTree(dirPath, new SimpleFileVisitor<Path>() {
#Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
size.addAndGet(attrs.size());
return FileVisitResult.CONTINUE;
}
#Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
//just skip
return FileVisitResult.CONTINUE;
}
});
return size.get();
}
}
/**
* Main method.
*
* #param args
*/
public static void main(String [] args) {
Path p = Paths.get("d:\\octopress");
try {
Files.walkFileTree(p, EnumSet.noneOf(FileVisitOption.class), 1, new PrintFiles());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Keep it short and simple by using FileUtils.sizeOfDirectory(). You have to import org.apache.commons.io.FileUtils for this.
if (temp.isDirectory()) {
File dirs = new File(temp.getPath());
System.out.println("DIR - " + dirs+" "+ friendlyFileSize(FileUtils.sizeOfDirectory(dirs)));
}
Staying close to what you've already done, you would have to increment the directory size everytime you encounter it.
for (File temp : filesNames) {
if (temp.isDirectory()) {
dirs = new File(temp.getPath());
heavy += getDirSize(dirs);
} else {
System.out.println("FILE - " + temp.getPath() + " "
+ friendlyFileSize(temp.length()));
}
}
You also would want to display the the size after summing it all up against the parent of the subdirectories
public static void main(String[] args) {
...
...
System.out.println("DIR - " + dirs.getParent() + " "
+ friendlyFileSize(heavy));
}
Also, you need to check for whether the directory has any files or not, else dirs.listFiles() would cause a NPE
private static long getDirSize(File dirs) {
long size = 0;
if (dirs != null && dirs.listFiles() != null) {
for (File file : dirs.listFiles()) {
if (file.isFile())
size += file.length();
else
size += getDirSize(file);
}
}
return size;
}
Your whole code slightly modified:
public class SubDirs {
static long heavy;
public static void main(String[] args) {
File file = new File("C:\\Program Files");
File dirs = null;
if (file.isDirectory()) {
File[] filesNames = file.listFiles();
for (File temp : filesNames) {
if (temp.isDirectory()) {
dirs = new File(temp.getPath());
heavy += getDirSize(dirs);
} else {
System.out.println("FILE - " + temp.getPath() + " "
+ friendlyFileSize(temp.length()));
}
}
} else {
System.out.println("THIS IS NOT A FILE LOCATION!");
}
System.out.println("DIR - " + dirs.getParent() + " "
+ friendlyFileSize(heavy));
}
private static long getDirSize(File dirs) {
long size = 0;
if (dirs != null && dirs.listFiles() != null) {
for (File file : dirs.listFiles()) {
if (file.isFile())
size += file.length();
else
size += getDirSize(file);
}
}
return size;
}
public static String friendlyFileSize(long size) {
String unit = "bytes";
if (size > 1024) {
size = size / 1024;
unit = "kb";
}
if (size > 1024) {
size = size / 1024;
unit = "mb";
}
if (size > 1024) {
size = size / 1024;
unit = "gb";
}
return " (" + size + ")" + unit;
}
}
Related
I want, if you try to copy to the directory, a message is displayed and the program shuts down. In the case of a file, display the file size and the time it was last modified. I don't know exactly, how can i show out file size, and last time modified.
..............................................................................................................................................................
import java.io.*;
public class KopeeriFail {
private static void kopeeri(String start, String end) throws Exception {
InputStream sisse = new FileInputStream(start);
OutputStream välja = new FileOutputStream(end);
byte[] puhver = new byte[1024];
int loetud = sisse.read(puhver);
while (loetud > 0) {
välja.write(puhver, 0, loetud);
loetud = sisse.read(puhver);
}
sisse.close();
välja.close();
}
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Did you gave name to the file");
System.exit(1);
}
kopeeri(args[0], args[0] + ".copy");
}
}
You can easily fetch BasicFileAttributes which stores size and last modification timestamp.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Specify file name");
return;
}
Path initial = Paths.get(args[0]);
if (!Files.exists(initial)){
System.err.println("Path is not exist");
return;
}
if (Files.isDirectory(initial)) {
System.err.println("Path is directory");
return;
}
BasicFileAttributes attributes = Files.
readAttributes(initial, BasicFileAttributes.class);
System.out.println("Size is " + attributes.size() + " bytes");
System.out.println("Last modified time " + attributes.lastModifiedTime());
Files.copy(initial, initial.getParent()
.resolve(initial.getFileName().toString() + ".copy"));
}
Hope it helps!
I am wondering if anyone can help me. I am only learning Java, what I am trying to do is read every file on c:\ and create a md5 hash of that file to compare at a later stage as well as displaying some basic counts and meta. I can't seem to recursively loop over every file and folder in the c:\ drive and I am not sure how to tackle creating an MD5 hash of each file. I am also not sure is this the best approach for so many files.
public static void main(String[] args) throws IOException {
int FileCount = 0,
DirCount = 0,
HiddenFiles = 0,
HiddenDirs = 0;
File folder = new File("/");
File[] listOfFiles = folder.listFiles();
for (File listOfFile : listOfFiles) {
Path file = listOfFile.toPath();
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
System.out.println("isOther: " + attr.isOther());
System.out.println("isRegularFile: " + attr.isRegularFile());
System.out.println("isSymbolicLink: " + attr.isSymbolicLink());
System.out.println("size: " + attr.size());
if (listOfFile.isFile()) {
System.out.println("File " + listOfFile.getName());
System.out.println("isHidden " + listOfFile.isHidden());
if (listOfFile.isHidden()) {
HiddenFiles++;
}
System.out.println("getPath " + listOfFile.getPath());
FileCount++;
} else if (listOfFile.isDirectory()) {
System.out.println("Directory " + listOfFile.getName());
System.out.println("isHidden " + listOfFile.isHidden());
System.out.println("getPath " + listOfFile.getPath());
if (listOfFile.isHidden()) {
HiddenDirs++;
}
DirCount++;
}
System.out.println("DirCount " + DirCount);
System.out.println("FileCount " + FileCount);
System.out.println("HiddenDirs " + DirCount);
System.out.println("HiddenFiles " + FileCount);
}
}
Let's create classes that will do it what do you want:
File, Folder
File is already exist, let's create class that has name XFile, not good but you will be find something better in future.
public class XFile {
private final File file;
public XFile(File file) {
this.file = file;
}
public String name() {
return file.getName();
}
//other data you want to know, create getters for all wanted information from File.
public byte[] md5() {
try (InputStream input = new BufferedInputStream(new FileInputStream(file))) {
MessageDigest md5 = MessageDigest.getInstance("MD5");
int tempByte;
while ((tempByte = input.read()) != -1) {
md5.update((byte) tempByte);
}
return md5.digest();
} catch (IOException | NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
and class Folder (that should be in jdk all this time)
public class Folder {
private final File underlyingDir;
private List<File> elements = null;
public Folder(File underlyingDir) {
this.underlyingDir = underlyingDir;
}
private void fetchElements() {
List<File> firstLevelElements = new ArrayList<>(Arrays.asList(underlyingDir.listFiles()));
elements = this.recursive(firstLevelElements, Integer.MAX_VALUE);
}
public List<XFile> files() {
if (elements == null) {
fetchElements();
}
return elements.stream()
.filter(File::isFile)
.map(XFile::new)
.collect(Collectors.toList());
}
public long foldersCount() {
if (elements == null) {
fetchElements();
}
return elements.stream()
.filter(File::isDirectory)
.collect(Collectors.toList())
.size();
}
public long filesCount() {
if (elements == null) {
fetchElements();
}
return elements.stream()
.filter(File::isFile)
.collect(Collectors.toList())
.size();
}
public long hiddenFiles() {
if (elements == null) {
fetchElements();
}
return elements.stream()
.filter(File::isFile)
.filter(File::isHidden)
.collect(Collectors.toList())
.size();
}
public long hiddenDirs() {
if (elements == null) {
fetchElements();
}
return elements.stream()
.filter(File::isDirectory)
.filter(File::isHidden)
.collect(Collectors.toList())
.size();
}
private List<File> recursive(List<File> elements, int depth) {
if (depth == -1) return Collections.emptyList();
List<File> result = new ArrayList<>();
for (File element : elements) {
if (element.isDirectory()) {
depth--;
result.add(element);
if (nonNull(element.listFiles())) {
result.addAll(recursive(Arrays.asList(element.listFiles()), depth));
}
} else {
result.add(element);
}
}
return result;
}
}
and test class Main
public class Main {
public static void main(String[] args) {
Folder folder = new Folder(new File("F:/"));
System.out.println("files " + folder.filesCount());
System.out.println("folders " + folder.foldersCount());
System.out.println("hidden dirs " + folder.hiddenDirs());
System.out.println("hidden files " + folder.hiddenFiles());
for (XFile file : folder.files()) {
System.out.printf("\nname: %s MD5 hash %s ", file.name(), Arrays.toString(file.md5()));
}
}
}
I have a program that should process the files in the directory and if the file size is more than 50 bytes delete it. Otherwise, if the file size is less then 50 bytes program should rename the args[1] file to the allFilesContent.txt(same directory), and write all the files to this file, separated by "n" (110 ASCII code). But instead the program just creates another file and writes to the very first args[1] file. What's the problem?
public class Solution
{
public static void main(String [] args) throws IOException
{
File path = new File(args[0]);
File resultFileAbsolutePath = new File(args[1]);
ArrayList<File> allFiles = new ArrayList<>();
boolean isRenamed = false;
for(File file : path.listFiles())
{
if(file.length() > 50)
{
FileUtils.deleteFile(file);
}
else if(file.length() <= 50)
{
if(!isRenamed)
{
FileUtils.renameFile(resultFileAbsolutePath, new File(resultFileAbsolutePath.getParent()+"\\allFilesContent.txt"));
isRenamed = true;
}
if(!file.getName().equals(resultFileAbsolutePath.getName()))
{
allFiles.add(file);
}
}
}
Collections.sort(allFiles, new Comparator<File>()
{
#Override
public int compare(File o1, File o2)
{
return o1.getName().compareTo(o2.getName());
}
});
FileOutputStream fileOutputStream = new FileOutputStream(resultFileAbsolutePath, true);
for (File file : allFiles)
{
try(FileInputStream fileInputStream = new FileInputStream(file))
{
if(allFiles.indexOf(file) != 0) fileOutputStream.write(110);
int data;
while(fileInputStream.available() > 0)
{
data = fileInputStream.read();
fileOutputStream.write(data);
}
}
}
fileOutputStream.close();
}
public static void deleteFile(File file)
{
if (!file.delete())
{
System.out.println("Can not delete file with name " + file.getName());
}
}
}
And FileUtils class
import java.io.File;
public class FileUtils
{
public static void deleteFile(File file)
{
if (!file.delete())
{
System.out.println("Can not delete file with name " + file.getName());
}
}
public static void renameFile(File source, File destination)
{
if (!source.renameTo(destination))
{
System.out.println("Can not rename file with name " + source.getName());
}
}
}
You have following statement: "FileOutputStream fileOutputStream = new FileOutputStream(resultFileAbsolutePath, true);"
Instead of "true" put "false". It should work.
Please mention me the link if this is a duplicate and has the apt answer.
The actual theme of my project is to copy a '.zip' file (installation file) from the local server to any machines based on OS. Let the path be //123.1.23.3.
In windows i can copy it directly like FileUtils.copyFiles(srcFile, destFile).
In Linux, I don know how to achieve it. I even did like considering the srcFile to be SmbFile(i.e samba file) and the destFile to be a File and the problem here is, either i should use
`FileUtils.copyFiles(srcFile, destFile)`. (If both of them are 'File's)
or
`srcFile.copyTo(destFile)` (If both files are 'SmbFile's)
but both is not possible here bcoz srcFile - SmbFile(file in local server) and destFile - File(local drive).
If anyone advice me to use streams to copy it, is there any way in linux to directly copy a zip file without extracting it as i did in windows (in a single step).
Because i have a seperate methods to extract or tar the files in windows and linux respectively, and if i use streams here i need to extract it and there would no need of the above seperate methods.
i think i made it clear.Thank u.
it can be achieved using IOUtils.copy(src.getInputStream(), new FileOutputStream(destFile));
Hi you can use the JAVA NIO package for the file copy utility
import java.nio.file.*;
import static java.nio.file.StandardCopyOption.*;
import java.nio.file.attribute.*;
import static java.nio.file.FileVisitResult.*;
import java.io.IOException;
import java.util.*;
public class Copy {
/**
* Returns {#code true} if okay to overwrite a file ("cp -i")
*/
static boolean okayToOverwrite(Path file) {
String answer = System.console().readLine("overwrite %s (yes/no)? ", file);
return (answer.equalsIgnoreCase("y") || answer.equalsIgnoreCase("yes"));
}
/**
* Copy source file to target location. If {#code prompt} is true then
* prompt user to overwrite target if it exists. The {#code preserve}
* parameter determines if file attributes should be copied/preserved.
*/
static void copyFile(Path source, Path target, boolean prompt, boolean preserve) {
CopyOption[] options = (preserve) ?
new CopyOption[] { COPY_ATTRIBUTES, REPLACE_EXISTING } :
new CopyOption[] { REPLACE_EXISTING };
if (!prompt || Files.notExists(target) || okayToOverwrite(target)) {
try {
Files.copy(source, target, options);
} catch (IOException x) {
System.err.format("Unable to copy: %s: %s%n", source, x);
}
}
}
/**
* A {#code FileVisitor} that copies a file-tree ("cp -r")
*/
static class TreeCopier implements FileVisitor<Path> {
private final Path source;
private final Path target;
private final boolean prompt;
private final boolean preserve;
TreeCopier(Path source, Path target, boolean prompt, boolean preserve) {
this.source = source;
this.target = target;
this.prompt = prompt;
this.preserve = preserve;
}
#Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
// before visiting entries in a directory we copy the directory
// (okay if directory already exists).
CopyOption[] options = (preserve) ?
new CopyOption[] { COPY_ATTRIBUTES } : new CopyOption[0];
Path newdir = target.resolve(source.relativize(dir));
try {
Files.copy(dir, newdir, options);
} catch (FileAlreadyExistsException x) {
// ignore
} catch (IOException x) {
System.err.format("Unable to create: %s: %s%n", newdir, x);
return SKIP_SUBTREE;
}
return CONTINUE;
}
#Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
copyFile(file, target.resolve(source.relativize(file)),
prompt, preserve);
return CONTINUE;
}
#Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
// fix up modification time of directory when done
if (exc == null && preserve) {
Path newdir = target.resolve(source.relativize(dir));
try {
FileTime time = Files.getLastModifiedTime(dir);
Files.setLastModifiedTime(newdir, time);
} catch (IOException x) {
System.err.format("Unable to copy all attributes to: %s: %s%n", newdir, x);
}
}
return CONTINUE;
}
#Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
if (exc instanceof FileSystemLoopException) {
System.err.println("cycle detected: " + file);
} else {
System.err.format("Unable to copy: %s: %s%n", file, exc);
}
return CONTINUE;
}
}
static void usage() {
System.err.println("java Copy [-ip] source... target");
System.err.println("java Copy -r [-ip] source-dir... target");
System.exit(-1);
}
public static void main(String[] args) throws IOException {
boolean recursive = false;
boolean prompt = false;
boolean preserve = false;
// process options
int argi = 0;
while (argi < args.length) {
String arg = args[argi];
if (!arg.startsWith("-"))
break;
if (arg.length() < 2)
usage();
for (int i=1; i<arg.length(); i++) {
char c = arg.charAt(i);
switch (c) {
case 'r' : recursive = true; break;
case 'i' : prompt = true; break;
case 'p' : preserve = true; break;
default : usage();
}
}
argi++;
}
// remaining arguments are the source files(s) and the target location
int remaining = args.length - argi;
if (remaining < 2)
usage();
Path[] source = new Path[remaining-1];
int i=0;
while (remaining > 1) {
source[i++] = Paths.get(args[argi++]);
remaining--;
}
Path target = Paths.get(args[argi]);
// check if target is a directory
boolean isDir = Files.isDirectory(target);
// copy each source file/directory to target
for (i=0; i<source.length; i++) {
Path dest = (isDir) ? target.resolve(source[i].getFileName()) : target;
if (recursive) {
// follow links when copying files
EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
TreeCopier tc = new TreeCopier(source[i], dest, prompt, preserve);
Files.walkFileTree(source[i], opts, Integer.MAX_VALUE, tc);
} else {
// not recursive so source must not be a directory
if (Files.isDirectory(source[i])) {
System.err.format("%s: is a directory%n", source[i]);
continue;
}
copyFile(source[i], dest, prompt, preserve);
}
}
}
}
Basically i wrote a program that will show a list of Files and Directories is a folder that is selected.
What I'm trying to do is to just show a number of File and Directories in that selected folder but all it show's me is the list of the files in that folder.
to explain it more clearly this is my code and run it to understand what the program is doing and my question is basically how to just show the number of files and directories in that folder.
import java.io.File;
public class DirectoryAnalyser {
public static void main(String[] args) {
DirectoryAnalyser stats = new DirectoryAnalyser();
stats.processFile(".");
stats.displayStatistics();
}
private int numFiles;
private int numDirectories;
public DirectoryAnalyser() {
numFiles = 0;
numDirectories = 0;
}
public void processFile(String file) {
File root = new File(file);
File[] list = root.listFiles();
for (File f : list){
if(f.isDirectory()){
processFile(f.getAbsolutePath());
System.out.println("Dir:" + f.getAbsoluteFile());
}else if(f.isFile()){
System.out.println("File:" + f.getAbsoluteFile());
}
}
}
public void displayStatistics() {
}
}
You need to that your processFile(String) method to count the number of files and dirs and print after it discover it. It will be something like:
public void processFile(String file) {
File root = new File(file);
File[] list = root.listFiles();
this.numFiles = 0;
this.numDirectories = 0;
for (File f : list) {
if (f.isDirectory()) {
numDirectories++;
processFile(f.getAbsolutePath());
} else if (f.isFile()) {
numFiles++;
}
}
}
public void displayStatistics() {
System.out.format("Total of file: %d\nTotal of directories: %d\n", numFiles, numDirectories);
}
It would be better if you didnt keep a state in your class and returned a class that contains the results and then you print it.
OK. I'll give you a hint.
This is what your displayStatistics() method should look like:
public void displayStatistics() {
System.out.println("Number of files: " + numFiles);
System.out.println("Number of directories: " + numDirectories);
}
Now all is left is to find proper places to increment these two counters.
this is the full code of my answer to my question, and thank u for every one that helped.
import java.io.File;
public class DirectoryAnalyser {
public static void main(String[] args) {
DirectoryAnalyser stats = new DirectoryAnalyser();
stats.processFile("/Users/ThamerMashhadi/Desktop/");
stats.displayStatistics();
}
private int numFiles;
private int numDirectories;
public DirectoryAnalyser() {
}
public void processFile(String file) {
File root = new File(file);
File[] list = root.listFiles();
for (File f : list) {
if (f.isDirectory()) {
numDirectories++;
processFile(f.getAbsolutePath());
// System.out.println("Directories:" + f.getAbsoluteFile());
} else if (f.isFile()) {
numFiles++;
// System.out.println("File:" + f.getAbsoluteFile());
}
}
}
public void displayStatistics() {
System.out.println("Total of file:" + numFiles);
System.out.println("Total of directories:" + numDirectories);
}
}