Merubah Contoh Reader atau Writer
Program ini menggunakan teknik dari perangkaian stream dimana class FileReader dan FileWriter didekorasi dengan class BufferedReader dan BufferedWriter.
----------------------
sintax sbb :
----------------------
public class CopyFile2 {
void copy(String input, String output) {
BufferedReader reader;
BufferedWriter writer;
String data; //yang membedakan tampilan data
try { //sehingga data berupa jadi satu meskipun dienter karena string
reader = new BufferedReader(new FileReader(input));
writer = new BufferedWriter(new FileWriter(output));
while ((data = reader.readLine()) != null) {
writer.write(data, 0, data.length());
}
reader.close();
writer.close();
} catch (IOException ie) {
ie.printStackTrace();
}
}
public static void main(String args[]) {
String inputFile = "c:\\aaaa.txt";
String outputFile = "d:\\cf2.txt";
CopyFile2 cf = new CopyFile2();
cf.copy(inputFile, outputFile);
}
}
void copy(String input, String output) {
BufferedReader reader;
BufferedWriter writer;
String data; //yang membedakan tampilan data
try { //sehingga data berupa jadi satu meskipun dienter karena string
reader = new BufferedReader(new FileReader(input));
writer = new BufferedWriter(new FileWriter(output));
while ((data = reader.readLine()) != null) {
writer.write(data, 0, data.length());
}
reader.close();
writer.close();
} catch (IOException ie) {
ie.printStackTrace();
}
}
public static void main(String args[]) {
String inputFile = "c:\\aaaa.txt";
String outputFile = "d:\\cf2.txt";
CopyFile2 cf = new CopyFile2();
cf.copy(inputFile, outputFile);
}
}
----------------------
hasil sbb :
----------------------Hasilnya akan membentuk sebuah baris seperti diatas.
Selamat mencoba, Good Luck :)
0 komentar:
Posting Komentar