/**
*
*/
package org.lei.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import org.apache.jasper.tagplugins.jstl.core.If;
/**
* @author renlei
* @E-mail:renlei0109@yeah.net
* @version 创建时间:2014-6-5 下午3:15:26 简单说明
*/
public class FileCopy {
public static void main(String []args) throws Exception{
File file = null;
file = new File("21-03.mp3");
File file3 = new File("renlei/lei3/4.mp3");
if(!file.exists()){
System.out.println("找不到该文件");
return ;
}
if(!file3.getParentFile().exists()){//其所在的文件夹不存在
file3.getParentFile().mkdirs();//新建其所在的文件夹
FileInputStream fin = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(file3);
byte []b = new byte[1024];
int len ;
while((len=fin.read(b))>0){
fos.write(b, 0, len);
}
}
System.out.println(file3.getAbsolutePath());//F:\my project\eclipse\xiaoyuandingcan\renlei\lei3\4.mp3
System.out.println(file3.getPath());//renlei\lei3\4.mp3
System.out.println(file3.getCanonicalPath());//F:\my project\eclipse\xiaoyuandingcan\renlei\lei3\4.mp3
System.out.println(file3.getParentFile());///renlei\lei3
}
}