Java FilePath文件夹找到

时间:2016-02-17 17:54:45

标签: java filepath

我的问题有解决办法吗?我希望使用文件,我每次运行都会添加到我的程序中,例如folder1,folder2,这个文件夹包含.txt文件。我怎样才能用Java语言编写它?

下一个问题是,当一些文件名为FileInfo和一些FileInformations时,如何为我的程序设置Uni。

      pdfManager.setFilePath("D:\\virusTotal\\FileInfo.pdf");

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

要阅读所有文件夹名称: -

File file = new File("C:\\"); // the directory under which you want to read folder names from 
String[] names = file.list();

for(String name : names)
{
    if (new File("C:\\" + name).isDirectory()) // name array has all folders and files now we take only the folders in that
    {
       System.out.println(name); // print out the current folder name

       String filesInsideFolder[] = new File("C:\\"+name).list(); // stores all files in the current folder in name variable to the array
       // type your db insert code here
       /*
          for example if you have already connected to database and registered and opened a connection then you can
          simply execute the below code here:-

            for(String files : filesInsideFolder)
            {
              String sql = "INSERT INTO Registration " + "VALUES ("+name+","+files+")";
              stmt.executeUpdate(sql);
            }
       */
    }
}