1 57 58 import java.io.*; 59 import java.util.*; 60 61 import org.apache.oro.text.perl.*; 62 63 71 public final class printPasswd { 72 public static final String [] fieldNames = { 73 "Login: ", "Encrypted password: ", "UID: ", "GID: ", "Name: ", 74 "Home: ", "Shell: " 75 }; 76 77 public static final void main(String args[]) { 78 BufferedReader input = null; 79 int field, record; 80 String line; 81 Enumeration fields; 82 Perl5Util perl; 83 84 try { 85 input = new BufferedReader(new FileReader("/etc/passwd")); 86 } catch(IOException e) { 87 System.err.println("Could not open /etc/passwd."); 88 e.printStackTrace(); 89 System.exit(1); 90 } 91 92 perl = new Perl5Util(); 93 record = 0; 94 95 try { 96 while((line = input.readLine()) != null) { 97 fields = perl.split("/:/", line).elements(); 98 field = 0; 99 100 System.out.println("Record " + record++); 101 102 while(fields.hasMoreElements() && field < fieldNames.length) 103 System.out.println(fieldNames[field++] + 104 (String )fields.nextElement()); 105 106 System.out.print("\n\n"); 107 } 108 } catch(IOException e) { 109 System.err.println("Error reading /etc/passwd."); 110 e.printStackTrace(); 111 System.exit(1); 112 } finally { 113 try { 114 input.close(); 115 } catch(IOException e) { 116 System.err.println("Could not close /etc/passwd."); 117 e.printStackTrace(); 118 System.exit(1); 119 } 120 } 121 122 } 123 124 } 125 | Popular Tags |