Java determine drive pathname


Complete source code below will show you how to determine a pathname is a pathname for drive or not.

*********************************************************************
COMPLETE SOURCE CODE FOR : PathnameIsDrive.java
*********************************************************************


import javax.swing.JOptionPane;
import javax.swing.filechooser.FileSystemView;

import java.io.File;

public class PathnameIsDrive
{
public static void main(String[]args)
{
//Create file instance from pathname
//Try change to pathname that match any drive in your computer
//For example C:\\ for C drive.
File myFile=new File("C:\\");

//Check whether the given pathname is drive or not
if(FileSystemView.getFileSystemView().isDrive(myFile))
{
System.out.println("This is a drive");
}
else
{
System.out.println("This is not a drive");
}
}
}


*********************************************************************
JUST COMPILE AND EXECUTE IT
*********************************************************************