java 复制文件至另一文件夹
当我们需要导出简历或者一些复杂数据表格时,自己去设置表格样式太繁琐,代码量大。这时候就可以用复制文件的方法。把需要的excel模板文件存储在指定文件夹,在复制一份,进行数据的填充。这样就可以节省很多的代码量。下面是复制文件的代码
public String file()throws IOException{
String folderPath="/app/file/notice/files/temp/resume/";//F:excel/stuInfoExcel
File oldfile = new File(folderPath+"员工简历模板.xls");//事先存储的模板文件
File newfile=new File(folderPath+"员工简历.xls");//创建新抽象文件
FileInputStream fin=new FileInputStream(oldfile);//输入流
FileOutputStream fout=new FileOutputStream(newfile,true);//输出流
byte[]b=new byte[1024];
while((fin.read(b))!=-1) {//读取到末尾 返回-1 否则返回读取的字节个数
fout.write(b);
}
fin.close();
fout.close();
return folderPath+"员工简历.xls";//返回文件路径
}