1.数据源分为源数据源和目标数据源
输入流联系的是源数据源
输出流联系的是目标数据源
2.文本文件的读写
i.用FileInputStream和FileOutputStream读写文本文件
FileInputStream常用的构造方法:FileInputStream(File file)
FileInputStream(String name)
FileOutputStream常用的构造方法:FileOutputStream(File file)
FileOutputStream(String name)
FileOutputStream(String name,boolean append)
前两种构造方法在向文件写数据时将覆盖文件中原有的内容
ii.用BufferReader和BufferWriter读写文本文件
iii.二进制文件的读写:使用DataInputStream和DataPutputStream读写二进制文件
3.File类的常用方法:
方法名称 | 说明 |
boolean exists() | 判断文件或目录是否存在 |
boolean isFile() | 判断是否是文件 |
boolean isDirectory() | 判断是否是目录 |
String getPath() | 返回此对象表示的文件的相对路径名 |
String getAbsolutePath() | 返回此对象表示的文件的绝对路径名 |
String getName() | 返回此对象表示的文件或目录的名称 |
boolean delete() | 删除此对象指定的文件或目录 |
boolean createNewFile() | 创建名称的空文件,不创建文件名 |
long length() | 返回文件的长度,单位为字节,若文件不存在,则返回OL |