本文介绍了查看目录和子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这对我来说,整个Java还是一个新事物,我正在尝试通过构建自己的东西来列出我音乐收藏中的所有文件夹和子文件夹(这很多)来学习它

到目前为止,我已经完成了以下代码,它循环遍历并为每个文件夹重复列出顶层大约10次.我只是在修改它之前就做了它.

谁能帮我更正它,并列出所有文件夹??

Ok so this whole Java thing is a still new to me and I am trying to learn it by building myself something to list all the folders and subfolders i have in my music collection (this is a lot)

I have the following code done so far and it loops through and lists the top level repeatly about 10 times for each folder. I had it just doing it one before i changed it.

Could anyone help me correct it and have it listing all folders??

public static void main(String args[]){
   File file = new File("D:\\music");
   File[] files = file.listFiles();
   for (int fileInList = 0; fileInList < files.length; fileInList++)
   {
         if (file.isDirectory()){

            File[] subFolder = file.listFiles();
            for (int i=0; i< subFolder.length; i++) {
                FoldersOnly(new File(files, subFolder[i]));

   System.out.println(files[fileInList].toString());
   }
       }
    }
}
}




我一直在使用Interent和书籍来帮助我达到这一目标,但是我无法做到最后一点.根据Netbeans,该错误似乎在FoldersOnly代码行中,但我无法使其正常工作.




I have been using the interent and books to help me get this far but i just cant get the last bit right. The error seems to be in the FoldersOnly line of code according to Netbeans but I just cant get it to work.

推荐答案


这篇关于查看目录和子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 12:09
查看更多