内存属于临时存储设备,断电、程序运行结束,内存释放,数据就消失。
持久化存储设备:数据可以这类设备上长久的保存。硬盘、U盘、光盘、磁带、软盘、云盘等。这些设备都可以长久的保存数据,当需要数据的时候,可以到这些设备上获取数据。
在前面学习的程序中数据最终都内存中,不是存在硬盘中,一旦程序停止运行,整个程序中的数据就没有了,
IO技术就是把程序中的数据最终输出到持久设备上。或者从设备读取已经存在的数据,最后给我们读取到程序中。
input 输入:读操作
output输出 :写操作
file类介绍在Java中使用File 这个类来描述持久设备上的文件或者文件夹。
文件:是用来保存真实的数据的。
文件夹:管理文件和文件夹。
file常用方法package file;
import java.io.File;
public class Demo {
public static void main(String[] args) {
// 文件夹
File file1 = new File("D:/Bandzip");
// 文件
File file2 = new File("D:/Bandzip/hi.txt");
// 判断文件是否存在
boolean exists = file1.exists();
// 判断是否是目录
boolean isDirectory = file1.isDirectory();
// 返回相对路径名
String getPath = file1.getPath();
// 返回绝对路径名
String absolutePath = file1.getAbsolutePath();
// 返回文件或文件夹的名称
String getName = file1.getName();
// 创建空文件,不创建文件夹
// boolean createNewFile = file1.createNewFile("");
System.out.println("exists:"+exists);
System.out.println("isDirectory:"+isDirectory);
System.out.println("getPath:"+getPath);
System.out.println("absolutePath:"+absolutePath);
System.out.println("getName:"+getName);
// 判断是否是文件
boolean file = file2.isFile();
// 返回文件长度
long length2 = file2.length();
System.out.println("file:"+file);
System.out.println("length2:"+length2);
}
}



