Minggu, 18 April 2010

Java seqfile1

import java.io.*;

class NilaiMatKul{
String nim;
String nama;
String nilai;

NilaiMatKul(){
}
}

class SeqFile1{

public static void main(String[] args) {

NilaiMatKul rekaman = new NilaiMatKul();

File fArsipMatKul;

fArsipMatKul = new File("ArsipMatKul.dat");

if(!fArsipMatKul.exists()){
try{
new File("ArsipMatKul.dat").
createNewFile();
}catch(Exception e){
}
}

try{
PrintWriter arsipMatKul = new PrintWriter(new FileWriter("ArsipMatKul.dat", false));

System.out.println("Tuliskan rekaman satu per satu");

try{
System.out.println("masukkan nim :");

BufferedReader is0 = new BufferedReader(

new InputStreamReader(System.in));

rekaman.nim = is0.readLine();
}catch(Exception e){
}
while(rekaman.nim.compareTo("XXXXXXXX") != 0){
/* proses */
try{
System.out.println("masukkan nama :");
BufferedReader is1 = new BufferedReader(

new InputStreamReader(System.in));

rekaman.nama = is1.readLine();

System.out.println("masukkan nilai :");
BufferedReader is2 = new BufferedReader(

new InputStreamReader(System.in));

rekaman.nilai = is2.readLine();

}catch(Exception e){
}

arsipMatKul.println(rekaman.nim + " " + rekaman.nama + " " + rekaman.nilai);
/* iterasi */
try{
System.out.println("masukkan nim :");
BufferedReader is = new BufferedReader(

new InputStreamReader(System.in));

rekaman.nim = is.readLine();
}catch(Exception e){
}
}

arsipMatKul.println("XXXXXXXX XXX X");
arsipMatKul.flush();
}catch(Exception e){
}


}
}