Get all absolute file paths in a given folder

I need to store in memory all the absolute paths of the file names in this directory.

myDirectory.list () - Returns String [] only of file names (without their absolute paths).

You do not want to use File Object as it consumes more memory.

Last thing - I can use the apache collection, etc. (but did not find anything useful for this).

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

This works, and I have to say that I'm confused when you say that you do not want to use File objects, but everything that works, I think.

+9
source

Does myDirectory not support the directory of all these files? If so, just connect the path in myDirectory to each of the cells in the myDirectory.list() array.

0
source

Source: https://habr.com/ru/post/952501/


All Articles