Here you can find the source of getDrive(File file)
public static File getDrive(File file)
//package com.java2s; import java.io.File; public class Main { public static File getDrive(File file) { File drive = null;/*from w ww.ja va2s .c om*/ for (File dr : File.listRoots()) { if (file.getAbsolutePath().toLowerCase() .startsWith(dr.getAbsolutePath().toLowerCase())) { drive = dr; break; } } return drive; } }