码迷,mamicode.com
首页 > 其他好文 > 详细

文件转移实际应用

时间:2014-08-26 15:18:46      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:blog   os   java   io   文件   for   ar   2014   div   

/*
 * @(#) 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();
		}
	}
}

  

文件转移实际应用

标签:blog   os   java   io   文件   for   ar   2014   div   

原文地址:http://www.cnblogs.com/wck1988/p/3937258.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!