Minggu, 18 April 2010

Java seqfile5

import java.io.*;

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

NilaiMatKul(){
}
}

class SeqFile5{

public static void main(String[] args) {

NilaiMatKul rekaman = new NilaiMatKul();

File arsipMatKul1;

File arsipMatKul2;

File fArsipMatKul;

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

arsipMatKul2 = new File("ArsipMatKul2.dat");

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

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

try{
PrintWriter arsipMatKul3 = new PrintWriter(new FileWriter("ArsipMatKul3.dat", false));

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


FileReader fr1 = new FileReader (arsipMatKul1);
BufferedReader in1 = new BufferedReader( fr1 );

FileReader fr2 = new FileReader (arsipMatKul2);
BufferedReader in2 = new BufferedReader( fr2 );

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

while(rekaman.nim.compareTo("XXXXXXXX") != 0){
arsipMatKul3.println(
rekaman.nim + " " + rekaman.nama + " " + rekaman.nilai);

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

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

while(rekaman.nim.compareTo("XXXXXXXX") != 0){
arsipMatKul3.println(
rekaman.nim + " " + rekaman.nama + " " + rekaman.nilai);

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

arsipMatKul3.println(
"XXXXXXXX XXX X");

arsipMatKul3.flush();
in1.close();
in2.close();
}catch(Exception e){
}
System.out.println("proses menyalin file selesai");





}
}