[英]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.