1 18 package se.mog.io; 19 20 import java.io.BufferedReader ; 21 import java.io.FileReader ; 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 import java.util.StringTokenizer ; 25 import java.util.Vector ; 26 27 33 class UnixFileSystem extends FileSystem { 34 35 public File[] listMounts() throws IOException { 36 37 BufferedReader reader = new BufferedReader (new FileReader ("/etc/mtab")); 38 try { 39 Vector mountPoints = new Vector (); 40 String line; 41 while ((line = reader.readLine()) != null) { 42 if (line.charAt(0) == '#') 43 continue; 44 Enumeration st = new StringTokenizer (line, " \t"); 45 if (!st.hasMoreElements()) 46 continue; 47 48 st.nextElement(); 49 if (!st.hasMoreElements()) { 50 System.err.println( 51 "WARN: /etc/mtab is corrupt, skipping line"); 52 continue; 53 } 54 mountPoints.add(new File((String ) st.nextElement())); 56 62 } 63 return (File[]) mountPoints.toArray(new File[mountPoints.size()]); 64 } finally { 65 reader.close(); 66 } 67 } 68 69 public static void main(String args[]) throws IOException { 70 File mounts[] = new UnixFileSystem().listMounts(); 71 for (int i = 0; i < mounts.length; i++) { 72 System.out.println(mounts[i]); 73 } 74 } 75 76 public native DiskFreeSpace getDiskFreeSpace(File file); 77 } 78 | Popular Tags |