copy file复制文件
public static void copyFile(String modelPath, String targetPath){ File model = new File(modelPath); File target = new File(targetPath); //如果文件不存在就创建出来 if(!target.getParentFile().exists()){ target.getParentFile().mkdirs(); } InputStream fileInS = null; OutputStream fileOuS = null; if(model.exists()){ try { fileInS = new FileInputStream(model); fileOuS = new FileOutputStream(target); } catch (FileNotFoundException e) { System.out.println("文件未找到!"); e.printStackTrace(); } int byteRead = 0; byte[] buffer = new byte[1444]; try { while((byteRead = fileInS.read(buffer)) != -1){ fileOuS.write(buffer, 0, byteRead); } } catch (IOException e) { System.out.println("===========从模板文件读取时报错!==========="); } finally { try { if(fileInS != null) fileInS.close(); } catch (IOException e) { System.out.println("===========输入流关闭报错!==========="); e.printStackTrace(); } try { if(fileOuS != null) fileOuS.close(); } catch (IOException e) { System.out.println("===========输出流关闭报错!==========="); e.printStackTrace(); } } }else{ System.out.println("===========BatchDownloadAction2中复制模板文件不存在!==========="); } }move移动
public static boolean Move(String srcFile, String destPath) { // File (or directory) to be moved File file = new File(srcFile); // Destination directory File dir = new File(destPath); // Move file to new directory boolean success = file.renameTo(new File(dir, file.getName())); return success; }