Java – get the absolute path of all files in a given folder

I need to save all the file names and absolute paths in a given directory in memory

myDirectory. List () – retrieves only string [] (without their absolute path) of file names

I don't want to use a file object because it consumes more memory

One last thing - I can use Apache collections, etc. (but I can't find anything useful)

Solution

String directory = <your_directory>;
String directory = <your_directory>;
File[] files = new File(directory).listFiles();
for(File file : files){
  if(file.isFile()){
    System.out.println(file.getAbsolutePath());
  }
}

This works. When you say you don't want to use the file object, I'll say I'm confused, but anyway, I guess

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>