课堂代码
import java.io.File;
public class Demo01 {
public static void main(String[] args) {
//展示树文件
File f = new File("d:/demo01");
printTree(f,0);
}
public static void printTree(File f , int level ){
for (int i = 0; i <level ; i ++){
System.out.println("\t");
}
System.out.println(f.getAbsolutePath());
if (f.isDirectory()){
level ++;
File[] strs = f.listFiles();
for ( int i = 0 ; i < strs.length; i ++ ){
File f0 = strs[i];
printTree(f0,level + 1);
}
}
}
}
import com.sun.javafx.iio.ios.IosDescriptor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
// 1 实现文件的复制
public class Demo02 {
public static void main(String[] args) throws Exception {
FileInputStream fi = null;
FileOutputStream fo = null;
try {
// 1 准备输入输出流
fi = new FileInputStream("D:\\alg\\ChromeSetup.exe");
fo = new FileOutputStream("C:\\dex\\chen_long.exe");
int len = 0;
byte[] b = new byte[1024];
while ((len = fi.read(b)) != -1) {
fo.write(b, 0, len);
}
} catch(IOException e){
System.out.println("文件路径不存在");
}
}
}
import java.io.*;
import java.util.Date;
public class Demo03 {
public static void main(String[] args) throws Exception {
BufferedInputStream fi = null;
BufferedOutputStream fo = null;
try {
// 1 准备输入输出流
fi = new BufferedInputStream(new FileInputStream("D:\\alg\\ChromeSetup.exe"));
fo = new BufferedOutputStream(new FileOutputStream("C:\\dex\\chen_long.exe"));
int len = 0;
byte[] b = new byte[1024];
long startTime = System.currentTimeMillis();
while ((len = fi.read(b)) != -1) {
fo.write(b, 0, len);
}
long endTime = System.currentTimeMillis();
System.out.println(endTime-startTime);
} catch (IOException e) {
System.out.println("文件路径不存在");
}
}
}
import jdk.internal.module.ModulePatcher;
import java.io.*;
public class Demo04 {
public static void main(String[] args) throws Exception{
Reader = new FileReader("E:\\xcdq.txt");
Writer = new FileWriter("D:\\edu\\atm.txt");
int len = 0;
char [] buffer = new char[1024];
ModulePatcher.PatchedModuleReader reader = null;
while ( (len = reader.read(buffer) ) != -1) {
writer.write(buffer , 0 , len);
}
reader.close();
writer.close();
}
}