Hi All,
I have wrote a java program, that displays all the drives available in the system. I used File.listRoots()
However, this method doesn't perform any security operations(such as read and write access) and displays all the drives in the system.
I want the program to display the only drives to which that particular user has access. For eg, if, among C,D,E,F , if user has access to D and F drives, I want to display only those drives.
I have written the following code, but every drive is throwing the securityException.
SecurityManager sm = new SecurityManager();
FilePermission fp;
//Object sc= getSecurityContext();
for(int i = 0; i < roots.length && sm!= null; i++) {
try
{
//sm.checkRead(roots[i].toString());
fp = new FilePermission(roots[i].toString(),"write");
sm.checkPermission(fp);
roots1[i] = new FileSystemRoot(roots[i]);
}
catch(SecurityException se)
{
}
catch(Exception e)
{
}
Am I Missing any thing here? Any suggestions are appreciated.
Cheers,
Vikram