Buffered input streams read data from a memory area known as a buffer;the native input API is called only when the buffer is empty. Similarly,buffered output streams write data to a buffer, and the native output API is called only when the buffer is full.
Example
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class CopyFiles {
public static void main(String[] args){
String sourceFileName = "D:\\Test Folder\\Test File.txt";
String destinationFileName = "D:\\Test Folder\\Test File 1.txt";
copyFile(sourceFileName, destinationFileName);
}
private static void copyFile(String sourceFileName,String destinationFileName) {
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new FileReader( sourceFileName ));
bw = new BufferedWriter(new FileWriter( destinationFileName ));
int c;
while ((c = br.read()) != -1) {
bw.write(c);
}
br.close();
bw.close();
}catch (Exception e) {
e.printStackTrace();
}
}
Advertisement