通过字符缓冲流复制字符类型文本文件
public static void copyByteFile(File source, File dest){
BufferedInputStream bufferedInputStream;
BufferedOutputStream bufferedOutputStream = null;
try {
if(source != null && dest != null) {
bufferedInputStream = new BufferedInputStream(new FileInputStream(source));
bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(dest));
int i;
while ((i = bufferedInputStream.read()) != -1) {
bufferedOutputStream.write(i);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(bufferedOutputStream != null) {
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
通过字节缓冲流对象复制流媒体文件
public static void copyCharFile(File source, File dest){
BufferedReader bufferedReader;
BufferedWriter bufferedWriter = null;
try {
if(source != null && dest != null) {
bufferedReader = new BufferedReader(new FileReader(source));
bufferedWriter = new BufferedWriter(new FileWriter(dest));
int temp;
while ((temp = bufferedReader.read()) != -1) {
bufferedWriter.write(temp);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(bufferedWriter != null) {
bufferedWriter.flush();
bufferedWriter.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}