public int copy() {
BufferedReader in = null;
FileInputStream fdr = null;
InputStreamReader is = null;
String fileIn = "1.txt";
String fileOut = "2.txt";
try {
File file = new File("D:\\rpt\\number\\1");
File fi = new File(file + "/" + fileIn);
File fo = new File(file + "/" + fileOut);
if (!file.exists()){
file.mkdir();
}
if (!fi.exists()) {
logger.info("文件不存在 无法复制!");
return 0;
}
if (fo.exists()){
fo.delete();
}
if (!fo.exists())
fo.createNewFile();
fdr = new FileInputStream(fi);
is = new InputStreamReader(fdr,"GBK");
in = new BufferedReader(is, 30 * 1024 * 1024);
String line = "";
RandomAccessFile raf = new RandomAccessFile(fo,"rw");
StringBuilder sb = new StringBuilder();
while ((line = in.readLine()) != null){
sb.append(line+"\r\n");
}
if (null != raf) {
raf.write(sb.toString().getBytes("UTF-8"));
logger.info("文件复制成功!");
raf.close();
}
}catch (Exception e){
logger.info("报错",e);
return -1;
}
return 0;
}