Hi,
I have some folder name in my system(eg:-e://xxx).Can i know that folder is located in E Drive through java Code.
Printable View
Hi,
I have some folder name in my system(eg:-e://xxx).Can i know that folder is located in E Drive through java Code.
Take a look at the API docs for File.
import java.io.*;
public class DirListing1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Boolean flag=false;
File f =new File("e:/");
String [] s=f.list();
for(int index =0 ; index<s.length;index++){
if(s[index].equals("e:/xxx")){
flag=true;
}
System.out.println(s[index]);
}
}
}
@DevzAbhi's code fragment starts with the explicit statement to look on E:
If the real question is: I have a directory somewhere, and its called XXX, how do I find it?
This is harder, because the concept of an E: drive is Windows specific,
You could, altho its crude, just run through a loop of all drive letters, A through Z, but with UNC names, that isn't guarenteed to be complete
I'm not clear what you are asking here. Are you want to find that a specific folder(as you said xxx) is located on drive E or not? So you have to search recursively all drives in the system.
But as fishtoprecords says, it's Widows specific, in UNC systems you don't have drive letters to find.
I said to look at File, because, if you do getParentFile() until it returns null, the "File" for which it returned null is the root for the File you started with.