博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SVN增量类
阅读量:4980 次
发布时间:2019-06-12

本文共 3314 字,大约阅读时间需要 11 分钟。

package com.dangjian.controller; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; public class FreePatchUtil {
public static String patchFile="F:/patch.txt";//生成的补丁文件,由eclipse svn plugin生成 public static String projectPath="D:/yunjike_workSpace";//项目所在文件夹路径(生成与项目匹配的目录) public static String webContent="WebContent";//web应用文件夹名 public static String desPath="F:/zengliangbao";//补丁文件包存放路径 (SVN创建补丁的时候选择的位置) //public static String version="20140711";//补丁版本 /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception {
Map
> map = getPatchFileListMap(); Set
keySet = map.keySet(); for (String key : keySet) {
List
fileList = map.get(key); copyFiles(fileList,key); } } public static Map
> getPatchFileListMap() throws Exception{ //List
fileList=new ArrayList
(); FileInputStream f = new FileInputStream(patchFile); BufferedReader dr=new BufferedReader(new InputStreamReader(f,"utf-8")); String line; Map
> map = new HashMap
>(); String webName = ""; while((line=dr.readLine())!=null){ if(line.indexOf("#P")!=-1){ line=line.replaceAll(" ",""); line=line.substring(line.indexOf("#P")+2,line.length()); webName = line; } if(line.indexOf("Index:")!=-1){ line=line.replaceAll(" ",""); line=line.substring(line.indexOf(":")+1,line.length()); List
fileList = map.get(webName); if(fileList==null){ fileList = new ArrayList
(); } fileList.add(line); map.put(webName, fileList); } } return map; } public static void copyFiles(List
list, String webName){ for(String fileName:list){ String fullFileName=projectPath+"/"+webName+"/"+fileName;//将要复制的文件全路径 String fullDesFileNameStr=desPath+"/"+webName+"/"+fileName; String desFilePathStr=fullDesFileNameStr.substring(0,fullDesFileNameStr.lastIndexOf("/")); File desFilePath=new File(desFilePathStr); if(!desFilePath.exists()){ desFilePath.mkdirs(); } copyFile(fullFileName, fullDesFileNameStr); System.out.println(fullDesFileNameStr); } } private static void copyFile(String sourceFileNameStr, String desFileNameStr) { File srcFile=new File(sourceFileNameStr); File desFile=new File(desFileNameStr); try { copyFile(srcFile, desFile); } catch (IOException e) { e.printStackTrace(); } } public static void copyFile(File sourceFile, File targetFile) throws IOException { BufferedInputStream inBuff = null; BufferedOutputStream outBuff = null; try { // 新建文件输入流并对它进行缓冲 inBuff = new BufferedInputStream(new FileInputStream(sourceFile)); // 新建文件输出流并对它进行缓冲 outBuff = new BufferedOutputStream(new FileOutputStream(targetFile)); // 缓冲数组 byte[] b = new byte[1024 * 5]; int len; while ((len = inBuff.read(b)) != -1) { outBuff.write(b, 0, len); } // 刷新此缓冲的输出流 outBuff.flush(); } finally { // 关闭流 if (inBuff != null) inBuff.close(); if (outBuff != null) outBuff.close(); } } }

转载于:https://www.cnblogs.com/woshuyuqiang/p/9275340.html

你可能感兴趣的文章