[英]reading files recursively and storing them java
public Vector readFiles(File Mydir) {
Vector<File> vec = new Vector<>(10,10); // to store the needed files
for (File f: Mydir.listFiles()){
if (!f.isDirectory()){
System.out.println("file found"+ f.getName());
vec.addElement(f);
// reads all the files in the directory recursively
} else
readFiles(f);
}
// System.out.println("size of vec = " + vec.size());
return vec;
}
嗨,我正在嘗試讀取目錄中的所有txt和pdf文件,並將它們存儲在vector中。 但是我的向量僅將其中4個作為元素添加! 我打印了文件,發現了所有文件,但未將它們添加到vec中。 謝謝你的幫助
遞歸調用方法時,不提供值向量:
readFiles(f);
每次通話都會覆蓋:
public Vector readFiles(File Mydir) {
Vector<File> vec = new Vector<>(10,10); // to store the needed files
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.