Minggu, 18 April 2010

Java seqfile2

import java.io.*;

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

NilaiMatKul(){
}
}

class SeqFile2{

public static void main(String[] args) {

NilaiMatKul rekaman = new NilaiMatKul();

File arsipMatKul;


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

System.out.println("isi arsip beruntun adalah :");

try{
FileReader fr = new FileReader (arsipMatKul);
BufferedReader in = new BufferedReader( fr );

String line = in.readLine();
String[] rekList = line.split("\\s+", 3);
rekaman.nim = rekList[0];
rekaman.nama = rekList[1];
rekaman.nilai = rekList[2];

if(rekaman.nim.compareTo("XXXXXXXX") == 0){
System.out.println("arsip kosong");
}
else{
do{
/* proses */
System.out.println("nim : " + rekaman.nim);
System.out.println("nama : " + rekaman.nama);
System.out.println("nilai : " + rekaman.nilai);
System.out.println("-----------------");

/* iterasi */
line = in.readLine();
rekList = line.split("\\s+", 3);
rekaman.nim = rekList[0];
rekaman.nama = rekList[1];
rekaman.nilai = rekList[2];
}while(rekaman.nim.compareTo("XXXXXXXX") != 0);
}
in.close();
}catch(Exception e){
}

}
}