```java
import java.io.File;
import java.io.IOException;
public class domo01 {
public static void main(String[] args) throws IOException {
File file1 = new File("D:\\暴风激活15.0.exe");
File file2 = new File("d:\\大电影");
File file3 = new File("d:/domo01/domo01.1");
File file4 = new File("d:/domo01/domo01.1");
File file5 = new File("D:\\test.txt");
File file6 = new File("D ://gesf");
// 1 创建一个文件
file2.createNewFile();
// 2 创建一个文件夹 mkdir 一个只能创建一个文件夹,如果父路径没有,则创建失败
boolean res = file3.mkdir();
System.out.println(res);
// 3 mkdirs 创建多个文件夹,如果父路径不存在,则一次性创建全部路径
file4.mkdirs();
// 4 删除文件
file2.delete();
// 5 renameTo 移动文件
file1.renameTo(new File(""));
// 6 exists
System.out.println(file2.exists());
// 7 isFile 是否是文件
System.out.println(file4.isFile());
// 8 isDirectory 是否是目录
System.out.println(file4.isDirectory());
// 9 getPath() 获取路径
System.out.println(file6.getPath());
}
}
package com.company;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class domo02 {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try { //1 准备输入输出流
fis = new FileInputStream(new File("c:/jdk8.0.2_windows-x64_bin.exe"));
fos = new FileOutputStream(new File("c:/jik8.exe"));
//2 循环读取操作
int len = 0;
long start = System.currentTimeMillis();
byte[] buff = new byte[1024];//开辟缓冲区
while ((len = fis.read(buff)) != -1) {
fos.write(buff, 0, len);
}
long end = System.currentTimeMillis();
System.out.println("时间" + (end - start));//1265
//3 关闭输入输出资源
fis.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}}
package com.company;
import java.io.*;
public class domo03{
public static void main(String[] args)throws Exception {
BufferedInputStream bis = null ;
BufferedOutputStream bos = null ;
try {
//1 准备输入输出流
bis=new BufferedInputStream( new FileInputStream(new File("c:/jdk8.0.2_windows-x64_bin.exe")));
bos=new BufferedOutputStream(new FileOutputStream(new File("c:/jik8.exe")));
//2 循环读取操作
int len=0;
byte[] buff=new byte[1024];//开辟缓冲区
long start = System.currentTimeMillis(); // 开始计时
while ((len=bis.read(buff))!=-1){
bos.write(buff, 0,len);
}
long end = System.currentTimeMillis(); // 结束计时
System.out.println("时间"+ ( end - start)); // 453ms
//3 关闭输入输出资源
bis.close();
bos.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
jpackage com.company;
import java.io.*;
public class domo04 {
public static void main(String[] args) throws IOException {
// reader 和 writer 只能操作文本内容
Reader reader = new FileReader("d:/1.txt");
FileWriter fileWriter = new FileWriter("d:/111.txt");
char [] buff = new char[1024];
int len = 0 ;
while ( ( len = reader.read(buff)) != -1) {
fileWriter.write(buff,0,len);
}
fileWriter.flush();
// 关闭资源
reader.close();
fileWriter.close();
}
}