import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;public class ReadFile {
public ReadFile() {
} /**
 * 删除某个文件夹下的所有文件夹和文件
 * 
 * @param delpath
 *            String
 * @throws FileNotFoundException
 * @throws IOException
 * @return boolean
 */
// public static boolean deletefile(String delpath) throws
// FileNotFoundException,
// IOException {
// try {
//
// File file = new File(delpath);
// if (!file.isDirectory()) {
// System.out.println("1");
// file.delete();
// }
// else if (file.isDirectory()) {
// System.out.println("2");
// String[] filelist = file.list();
// for (int i = 0; i < filelist.length; i++) {
// File delfile = new File(delpath + "\\" + filelist[i]);
// if (!delfile.isDirectory()) {
// System.out.println("path=" + delfile.getPath());
// System.out.println("absolutepath=" + delfile.getAbsolutePath());
// System.out.println("name=" + delfile.getName());
// delfile.delete();
// System.out.println("删除文件成功");
// }
// else if (delfile.isDirectory()) {
// deletefile(delpath + "\\" + filelist[i]);
// }
// }
// file.delete();
//
// }
//
// }
// catch (FileNotFoundException e) {
// System.out.println("deletefile() Exception:" + e.getMessage());
// }
// return true;
// }
/**
 * 读取某个文件夹下的所有文件夹和文件
 * 
 * @param delpath
 *            String
 * @throws FileNotFoundException
 * @throws IOException
 * @return boolean
 */
static int i = 0; public static boolean readfile(String filepath) { InputStream is = null;
OutputStream os = null;
File file = new File(filepath);
if (!file.isDirectory()) {
System.out.println("文件");
System.out.println("path=" + file.getPath());
System.out.println("absolutepath=" + file.getAbsolutePath());
try {
System.out.println("name="
+ new String((file.getName().getBytes()), "utf8"));
File file1 = new File(new String(("d:/4/"+file)
.getBytes(), "utf8"));
// File file1 = new File(new String(file.getAbsolutePath() System.out.println(file1.getAbsolutePath());
file1.createNewFile(); is = new FileInputStream(file);
os = new FileOutputStream(file1);
int len = 0;
while ((len = is.read()) != -1) { os.write(len);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } else {
System.out.println("文件夹");
File[] filelist = file.listFiles();
System.out.println(file.getAbsolutePath());
System.out.println(filelist.length);
for (int i = 0; i < filelist.length; i++) {
File readfile = filelist[i];
System.out.println(i);
System.out
.println("=============" + readfile.getAbsolutePath());
if (!readfile.isDirectory()) {
System.out.println("文件1");
System.out.println("path=" + readfile.getPath());
System.out.println("absolutepath="
+ readfile.getAbsolutePath());
try {
System.out.println("name="
+ new String(readfile.getName().getBytes(),
"utf8"));
File readfile1 = new File(new String(
("d:/4/" + readfile.getName()).getBytes(),
"utf8"));
// File readfile1 = new File(new String(readfile
// .getAbsolutePath().getBytes(), "utf8"));
readfile1.createNewFile(); is = new FileInputStream(readfile);
os = new FileOutputStream(readfile1);
int len = 0;
while ((len = is.read()) != -1) {
os.write(len);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } else {

File  filea=new File("d:/4/"+filelist[i].getName());
filea.mkdir();
readfile( filelist[i].getAbsolutePath());

}
} } return true;
} public static void main(String[] args) {
try {
readfile("d:/3");
// deletefile("D:/file"); } catch (Exception ex) {
ex.printStackTrace();
}
System.out.println("ok");
}}
这段程序怎样能把d盘3文件夹里的所有内容按文件目录都复制到4文件夹里