Javaレプリケーションファイルツールクラス


package com.yqq.touristmanager.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileUtils {

	public FileUtils() {
		// TODO Auto-generated constructor stub
	}
	/**
	 * @warning The name of file must be end with .xls
	 * @param res The resource file
	 * @param des The destination
	 * @return 
	 * @throws FileNotFoundException 
	 */
	public static boolean toCopy(String res,String des){
		boolean flag=false;
		Boolean bool1 = res.endsWith(".xxx");
		Boolean bool2 = des.endsWith(".xxxb");
		
		if(!bool1 && !bool2){
			return false;
		}
		//     
		File file = new File(res) ;
		FileInputStream fr=null;
		//      
		File desFile = new File(des);
		FileOutputStream bw=null;
		try {
			fr = new FileInputStream(file);
			bw = new FileOutputStream(desFile);
			
			//buffer
			byte[] b = new byte[512];
			while(fr.read(b)!=-1){
				bw.write(b);
			}
			bw.flush();
			flag=true;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(fr != null)
				try {
					fr.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			if(bw != null){
				try {
					bw.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return flag;
	}

}

.xxx形式のファイルを指定したパスにコピーします.