上で述べたことに少し問題があります。
参考までに、このプログラムの私のコードは次のとおりです。
import java.io.*;
import java.util.*;
public class DirectorySizeProcessor extends DirectoryProcessor
{
/*
Dan Czarnecki
October 17, 2013
Class variables:
private Vector<Long> directorySizeList
Variable of type Vector<Long> that holds the total file size of files in that directory
as well as files within folders of that directory
private Vector<File> currentFile
Variable of type Vector<File> that
Modification History
October 17, 2013
Original version of class
Implemented run() and processFile() methods
*/
private Vector<Long> directorySizeList;
private Vector<File> currentFile;
public DirectorySizeProcessor(File startingDirectory) throws FileNotFoundException
{
super(startingDirectory);
directorySizeList = new Vector<Long>();
currentFile = new Vector<File>();
}
/*
public void run()
{
File file;
file = directoryLister.next();
while(file != null) //the following will be called when the File object is not null
{
processFile(file);
file = directoryLister.next();
}
}
*/
public void processFile(File file)
{
Long hold;
Long currentSize;
Long finalTotal;
int index;
File parentFile;
parentFile = file.getParentFile();
index = this.currentFile.indexOf(parentFile);
if(index < 0)
{
this.directorySizeList.addElement((long)0);
this.currentFile.addElement(file.getParentFile());
}
while(index > 0)
{
currentSize = this.directorySizeList.get(index);
hold = file.length();
finalTotal = hold + currentSize;
//System.out.println("current size: " + parentFile);
//System.out.println("current size: " + currentSize);
System.out.println("file: " + file);
System.out.println("current size: " + file.length());
parentFile = parentFile.getParentFile();
index = this.getParentDirectory().indexOf(parentFile);
finalTotal = file.length() + finalTotal;
System.out.println("final total: " + finalTotal);
}
}
public void run()
{
File file;
file = directoryLister.next();
while(file != null) //the following will be called when the File object is not null
{
processFile(file);
file = directoryLister.next();
}
}
public Vector getParentDirectory()
{
return this.currentFile;
}
public Vector getDirectorySizeList()
{
return this.directorySizeList;
}
}
問題が主に私の processFile() メソッドにあることはわかっています。Driverクラスから(その中でprocessFile()メソッドを呼び出すrun()メソッドを介して)実行すると、個々のファイルのサイズ(バイト単位)が適切に表示されますが、計算しているとは思いませんプロパティウィンドウに表示されているサイズと一致しないため、ディレクトリ全体のサイズ。誰かがここで私を助けてくれますか?