文档库 最新最全的文档下载
当前位置:文档库 › CopyTexFile

CopyTexFile

?package com.niit.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
//纯文本的
public class CopyTexFile {

public static void copyCharFile(String src,String dest){

BufferedReader br = null;
BufferedWriter bw = null;

try {
br = new BufferedReader(new FileReader(src));
bw = new BufferedWriter(new FileWriter(dest));
String line = null;
while((line = br.readLine())!= null){
bw.write(line);
//换行的操作
bw.newLine();
bw.flush();
}

} catch (FileNotFoundException e) {
throw new RuntimeException("文件找不到");
} catch (IOException e) {
throw new RuntimeException("发生IO异常");
}finally{
if(br!=null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(bw!=null){
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}
public static void main(String[] args) {

copyCharFile("c:/1.xls","c:/dest/2.xls");

}


}

相关文档