Search entire computer for file name in Java

Is there a way to search the entire computer for a String value representing the file name in Java? That would be without knowing the drive names on the computer.

+3
source share
4 answers

You can iterate through the file system by looking at file names, retrieving content if it is a directory, etc. recursively.

If the gluing point is the way to get the disks on the computer, look at the File.listRoots () function for a list of drive letters.

ETA:

, . .. ( LINUX/UNIX, Windows).

, , File.getCanonicalPath, "" . getCanonicalFile , , , , , .

+6

File, , :

File file = new File("/"); //root

, ( ), :

if(tempFile.isDirectory())
     //do recursive call on that directory
else
     //perform check on file name
+2

. - . , Windows " " Windows, , , .

+1

: java.io.File:

0

All Articles