Minggu, 18 April 2010

Java seqfile4

import java.io.*;

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

NilaiMatKul(){
}
}

class SeqFile4{

public static void main(String[] args) {

NilaiMatKul rekaman = new NilaiMatKul();

File arsipMatKul1;

File fArsipMatKul;

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

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

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

try{
PrintWriter arsipMatKul2 = new PrintWriter(new FileWriter("ArsipMatKul.bak", false));

System.out.println("mulai proses menyalin file");


FileReader fr = new FileReader (arsipMatKul1);
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){
arsipMatKul2.println(
"XXXXXXXX XXX X");
}
else{ while(rekaman.nim.compareTo("XXXXXXXX") != 0){
arsipMatKul2.println(
rekaman.nim + " " + rekaman.nama + " " + rekaman.nilai);

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

arsipMatKul2.println(
"XXXXXXXX XXX X");
}
arsipMatKul2.flush();
in.close();
}catch(Exception e){
}
System.out.println("proses menyalin file selesai");



}
}