//writeGG.java --- you can use this example import java.io.*; import java.util.*; class writeGG { PrintStream cout=null; BufferedReader cin=null; PrintWriter pw = null; public static final String fileName="GG.txt"; public static void main(String xxx[ ]) { writeGG gg = new writeGG( ); gg.prepareIO( ); gg.main( ); } public writeGG( ) { } void prepareIO( ) { try{ cout = System.out; cin = new BufferedReader( new InputStreamReader(System.in) ); }catch(Exception e) {;} } //////// int main( ) { int nRec = 5 + (int)(Math.random( )*10.0); try { pw = new PrintWriter( new FileWriter(fileName)); }catch(Exception e) { return 0; } cout.printf("writting %d records into file: %s", nRec, fileName); for(int i=0; i < nRec; ++i) { genOneRec(i); }//for pw.close( ); cout.println( ); return 0; }//int main( ///////// void genOneRec(int i) { String ha[ ]={"Chang", "Lee", "Cage"}; int id = 9917000 + i; int n = (int)( ha.length * Math.random( )); // 0..2 String name = ha[n]; name += (char)('A' + (int)(26*Math.random( )) ); name += (char)('A' + (int)(26*Math.random( )) ); name += (char)('A' + (int)(26*Math.random( )) ); int gy = 75 + (int)(8*Math.random( ) ); pw.printf("%8d %10s %d\n", id, name, gy); }//genOneRec( }//writeGG /****************** C:\jtest\pone> javac writeGG.java C:\jtest\pone> java writeGG writting 14 records into file: GG.txt C:\jtest\pone> type GG.txt 9917000 ChangPBI 80 9917001 CageYJP 79 9917002 CageNPJ 75 9917003 LeeYIV 82 9917004 CageOTU 77 9917005 ChangLTL 75 9917006 LeeRCL 79 9917007 LeeOXK 78 9917008 CageEER 80 9917009 ChangGTH 82 9917010 LeeXGB 82 9917011 CageQAZ 75 9917012 LeeQXZ 77 9917013 ChangASH 77 C:\jtest\pone> ****************************/