• java复制项目中的补丁,完整的包路径


    package com.bytter.audit.iface.util;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.List;
    
    public class ExportClass {
    
    	public static void main(String[] args) throws IOException {
    		// 导出的补丁包路径
    		String exportBasePath = "E:\bug单\青海\2019稽核\补丁\"
    				+ new SimpleDateFormat("yyyy.MM.dd").format(new Date()) + "接口补丁";
    		File file = new File(exportBasePath);
    		if (!file.exists()) {
    			file.mkdirs();
    		}
    
    		String fileBasePath = "E:\work2019\jk_qhys";
    		List<String> list = getFileList();
    		System.out.println("待复制文件数量为:【"+list.size()+"】");
    		for (String sourceFile : list) {
    			String sourceDirPath = sourceFile.substring(0, sourceFile.lastIndexOf("/"));
    			String sourceFileName = sourceFile.substring(sourceFile.lastIndexOf("/")+1);
    			sourceFileName = sourceFileName.indexOf(".java") > 0
    					? sourceFileName.substring(0, sourceFileName.indexOf(".")) + ".class" : sourceFileName;
    
    			System.out.println("-----开始拷贝文件:"+sourceFileName);
    			// 要导出的文件路径
    			File dirTarget = new File(exportBasePath + sourceDirPath);
    			if (!dirTarget.exists()) {
    				dirTarget.mkdirs();
    			}
    			System.out.println("目标路径:"+dirTarget.getAbsolutePath());
    			File targetFile = new File(exportBasePath + sourceDirPath + File.separator + sourceFileName);
    			// 开始复制文件
    			File fileSource = new File(fileBasePath + sourceDirPath + File.separator + sourceFileName);
    			
    			copyFile(fileSource, targetFile);
    			System.out.println("......拷贝完成:"+sourceFileName);
    		}
    
    	}
    
    	private static List getFileList() {
    		String classFilePath = "\WebContent\WEB-INF\classes";
    		List<String> list = new ArrayList<String>();
    		list.add("/jk_qhys/JavaSource/com/bytter/audit/iface/bussiness/readftpfile/ActionReadFtpFile.java");
    		list.add("/jk_qhys/JavaSource/com/bytter/audit/iface/dumblyThread/dumblyThread.java");
    		list.add("/jk_qhys/JavaSource/com/bytter/audit/iface/dumblyThread/qhbasethread/BtAuditDaillyDataReadFileDZQD.java");
    		list.add("/jk_qhys/JavaSource/com/bytter/audit/iface/bussiness/IbtAuditFtpService.java");
    		list.add("/jk_qhys/JavaSource/com/bytter/audit/iface/bussiness/impl/BtAuditFtpService.java");
    		list.add("/jk_qhys/JavaSource/com/bytter/audit/iface/dumblyThread/qhbasethread/BtAuditDaillyDataReadFileDZQD.java");
    
    		List<String> lists = new ArrayList<String>();
    		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
    			String file = (String) iterator.next();
    			// class文件
    			if (file.indexOf("/com/") > -1) {
    				lists.add(classFilePath + file.substring(file.indexOf("/com/")));
    			}else if(file.indexOf("/WebContent/")>-1){
    				lists.add(file.substring(file.indexOf("/WebContent/")));
    			}
    		}
    		return lists;
    	}
    
    	// 复制文件
    	public static void copyFile(File sourceFile, File targetFile) throws IOException {
    		// 新建文件输入流并对它进行缓冲
    		FileInputStream input = new FileInputStream(sourceFile);
    		BufferedInputStream inBuff = new BufferedInputStream(input);
    
    		// 新建文件输出流并对它进行缓冲
    		FileOutputStream output = new FileOutputStream(targetFile);
    		BufferedOutputStream outBuff = new BufferedOutputStream(output);
    
    		// 缓冲数组
    		byte[] b = new byte[1024 * 5];
    		int len;
    		while ((len = inBuff.read(b)) != -1) {
    			outBuff.write(b, 0, len);
    		}
    		// 刷新此缓冲的输出流
    		outBuff.flush();
    
    		// 关闭流
    		inBuff.close();
    		outBuff.close();
    		output.close();
    		input.close();
    	}
    
    	class FileVo {
    		private String filePath;
    		private String fileName;
    
    		public FileVo() {
    			super();
    		}
    
    		public FileVo(String filePath, String fileName) {
    			super();
    			this.filePath = filePath;
    			this.fileName = fileName;
    		}
    
    		public String getFilePath() {
    			return filePath;
    		}
    
    		public void setFilePath(String filePath) {
    			this.filePath = filePath;
    		}
    
    		public String getFileName() {
    			return fileName;
    		}
    
    		public void setFileName(String fileName) {
    			this.fileName = fileName;
    		}
    
    	}
    
    }
    

      

  • 相关阅读:
    《软件需求十步走》阅读笔记一
    专业实训项目需求分析
    2015秋季学期个人阅读计划
    最后期限阅读笔记3
    最后期限阅读笔记2
    最后期限阅读笔记1
    你的灯亮着么阅读笔记3
    DPDK(二):准备知识7---linux虚拟网络设备
    DPDK(二)准备6---PMD
    DPDK(二):准备知识4 --- 无锁FIFO环形队列
  • 原文地址:https://www.cnblogs.com/chinazhou-wang/p/11271567.html
Copyright © 2020-2023  润新知