文件夹复制
package cn.demo9;
import java.io.*;
public class Demo2 {
private static FileInputStream fis =null;
private static FileOutputStream fos=null;
public static void main(String[] args)
{
String srcPathStr = "F:\\demo.txt";
String desPathStr = "F:\\Hello";
copy(srcPathStr, desPathStr);
}
public static void copy(String srcPathStr, String desPathStr) {
File startFile = new File(srcPathStr);
String startName=startFile.getName();
System.out.println("源文件:"+startName);
desPathStr=desPathStr+"\\"+startName;
System.out.println("目标文件地址:"+desPathStr);
try {
fis = new FileInputStream(srcPathStr);
fos = new FileOutputStream(desPathStr);
byte datas[] = new byte[1024*8];
int len = 0;
while((len = fis.read(datas))!=-1)
{
fos.write(datas,0,len);
}
}catch (Exception e) {
e.printStackTrace();
}finally {
try {
fis.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}