java 实现文件复制,并且更改格式
fbean.getAbsolutePath());// savePathNew = savePath + File.separator + fbean.getName()+ ".jpg"; // 把文件名称中含有.tbi格式的转化为.jpg格式 savePathNew = savePath + File.separator + (fbean.getName().replaceAll(".tbi", ".jpg")); // 开始复制 copy(fbean ,new File(savePathNew)); } } } /**拷贝文件 * * @author chen_weixian * Mar 11, 2012 11:31:59 PM * @param fromFile * @param toFile * @throws Exception */ private static void copy(File fromFile, File toFile) throws Exception{ if (!fromFile.exists()) { System.out.println("来源文件为空!"); } if (!toFile.exists()) { System.out.println("创建新文件。。"); toFile.createNewFile(); } FileInputStream fis = new FileInputStream(fromFile); System.out.println("fromFile :" + fromFile.getAbsolutePath()); FileOutputStream fos = new FileOutputStream(toFile); System.out.println("toFile :" + toFile.getAbsolutePath()); int len = 0; byte[] buf = new byte[1024]; while((len = fis.read(buf)) != -1){ fos.write(buf,0,len); } fis.close(); fos.close(); } /** 测试 * @author chen_weixian * Mar 11, 2012 10:19:56 PM * @param args */ public static void main(String[] args) {// String path = "E:/temp"; String path = "E:/temp/3月份数据包(1)/3月份数据包"; String savePath = "E:/temp/img"; Change2Image change2Image = new Change2Image(); try { change2Image.change2Image(path, savePath); } catch (Exception e) { e.printStackTrace(); } System.out.println("完成"); }}
?