package cn.itcast.Demo4133;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo2 {
public static void main(String[] args) throws IOException {
File file = new File("F:\\考试");
File toFile = new File("g:\\FF");
toFile.mkdir();
get(file, toFile);
}
public static void get(File file,File toFile) throws IOException{
//不复制文件夹,只复制文件夹中的文件
File[] str = file.listFiles();
for(File f:str){
if(f.isDirectory()){
get(f, toFile);
}else {
FileInputStream fis = new FileInputStream(f);
File file1 = new File(toFile,f.getName());
FileOutputStream fos = new FileOutputStream(file1);
byte[] by = new byte[1024];
int len = 0;
while((len = fis.read(by))!=-1){
fos.write(by,0,len);
}
fos.close();
fis.close();
}
}
//复制文件夹及文件夹中的内容
/*File[] str = file.listFiles();
for(File f:str){
File pinFile = new File(toFile,f.getName());
if(f.isDirectory()){
pinFile.mkdir();
get(f, pinFile);
}else {
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = new FileOutputStream(pinFile);
int len = 0;
byte[] by = new byte[1024];
while((len = fis.read(by))!=-1){
fos.write(by,0,len);
}
fis.close();
fos.close();
}
}*/
/* File pinFile = new File(toFile,file.getName());
if(file.isDirectory()){
File[] str = file.listFiles();
for(File f:str){
pinFile.mkdir();
get(f, pinFile);
}
}else {
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(pinFile);
byte[] by = new byte[1024];
int len = 0;
while((len = fis.read(by))!=-1){
fos.write(by,0,len);
}
fos.close();
fis.close();
}*/
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo2 {
public static void main(String[] args) throws IOException {
File file = new File("F:\\考试");
File toFile = new File("g:\\FF");
toFile.mkdir();
get(file, toFile);
}
public static void get(File file,File toFile) throws IOException{
//不复制文件夹,只复制文件夹中的文件
File[] str = file.listFiles();
for(File f:str){
if(f.isDirectory()){
get(f, toFile);
}else {
FileInputStream fis = new FileInputStream(f);
File file1 = new File(toFile,f.getName());
FileOutputStream fos = new FileOutputStream(file1);
byte[] by = new byte[1024];
int len = 0;
while((len = fis.read(by))!=-1){
fos.write(by,0,len);
}
fos.close();
fis.close();
}
}
//复制文件夹及文件夹中的内容
/*File[] str = file.listFiles();
for(File f:str){
File pinFile = new File(toFile,f.getName());
if(f.isDirectory()){
pinFile.mkdir();
get(f, pinFile);
}else {
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = new FileOutputStream(pinFile);
int len = 0;
byte[] by = new byte[1024];
while((len = fis.read(by))!=-1){
fos.write(by,0,len);
}
fis.close();
fos.close();
}
}*/
/* File pinFile = new File(toFile,file.getName());
if(file.isDirectory()){
File[] str = file.listFiles();
for(File f:str){
pinFile.mkdir();
get(f, pinFile);
}
}else {
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(pinFile);
byte[] by = new byte[1024];
int len = 0;
while((len = fis.read(by))!=-1){
fos.write(by,0,len);
}
fos.close();
fis.close();
}*/
}
}