首页 > 代码库 > 文件转移实际应用
文件转移实际应用
/* * @(#) TTTTest.java 2014年8月26日 上午9:52:37 * * Copyright 2014 Rockwell Automation, Inc. All rights reserved. * Rockwell Automation PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package mytestProject;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.util.HashMap;import java.util.Map;public class TTTTest{ public static void main(String[] args) { try { int byteread = 0; String fromPath = "E:\\捷豹路虎SVN\\09CJLR\\05工作日报"; String toPath = "E:\\公司SVN\\CJLR\\13 项目日报\\"; Map<String,String> colleagueMap = new HashMap<String,String>(); colleagueMap.put("ChongKai Wei", "韦崇凯"); colleagueMap.put("Deyang Li", "李德扬"); colleagueMap.put("Fangzhigang", "方志刚"); colleagueMap.put("HuangShiwei", "黄世伟"); colleagueMap.put("li naiping", "李乃平"); colleagueMap.put("Lin Hui", "林辉"); colleagueMap.put("Shengxi Liang", "梁生熙"); colleagueMap.put("Zhiping Shi", "石智平"); colleagueMap.put("Tim201", "刘德铭"); colleagueMap.put("zhangJian", "张健"); colleagueMap.put("zhangmingyu", "张鸣宇"); colleagueMap.put("Smile Shi", "施明楼"); File fromfile = new File(fromPath); // 浏览第一层文件 File[] files = fromfile.listFiles(); if (files == null) return; for (int i = 1; i < files.length; i++) { // 浏览第二层文件 File[] twofiles = files[i].listFiles(); if (twofiles == null) return; for (int j = 1; j < twofiles.length; j++) { if (twofiles[j].exists()) { String fileName = twofiles[j].getName(); String inString = ""; for(Map.Entry<String, String> entry: colleagueMap.entrySet()) { if(fileName.indexOf(entry.getKey())!=-1) { inString+=toPath+entry.getValue()+"\\"; } } if("".equals(inString)) { continue; } InputStream inStream = new FileInputStream(files[i].getPath()+"/" + twofiles[j].getName()); // 读入原文件 FileOutputStream fs = new FileOutputStream(inString + twofiles[j].getName()); byte[] buffer = new byte[1444]; while ((byteread = inStream.read(buffer)) != -1) { fs.write( buffer, 0, byteread); } fs.close(); inStream.close(); } } } } catch (Exception e) { e.printStackTrace(); } }}
文件转移实际应用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。