私のプログラムに問題があります。 ダウンロードしたファイルを最後までソートしようとしています。これまでのところ、特定のファイルパスを観察し、それらのファイルをHashSet
内にリストする構造があります。 私の問題は今、プログラムが数秒間実行されているが、終了コード0で終了するので、すべてが正常であるはずです。理由がなく連続スレッドを使用中にJVMが終了する
public class WatchDir {
protected HashSet<File> hashSetOfFiles;
protected String filePath = "";
public WatchDir() {
chooseFilePath();
if (filePath.isEmpty())
return;
listAnfangFiles();
new Thread() {
public void run() {
listNewFiles();
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();
}
private void listNewFiles() {
File file = new File(filePath);
for (File f : file.listFiles()) {
if (hashSetOfFiles.add(f)) {
newFileFound(f);
}
}
}
private void newFileFound(File f) {
// Hier kommen alle neuen Dateien an
System.out.println(f.getName());
}
private void listAnfangFiles() {
hashSetOfFiles = new HashSet<File>();
File f = new File(filePath);
for (File ff : f.listFiles()) {
hashSetOfFiles.add(ff);
}
}
private void chooseFilePath() {
//
// JFileChooser chooser = new JFileChooser();
// chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//
// if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
// filePath = chooser.getSelectedFile().getAbsolutePath();
filePath = "C:\\Users\\maurice\\Desktop\\Test";
}
public static void main(String[] args) {
new WatchDir();
}
}
ありがとうございます。あなたは何をすることをお勧めしますか? – mauricemertens
大丈夫、ありがとう:) – mauricemertens