标准输入/输出类System
标准输入流
out
Systm.out.println();
err
System.out.println();
标准输出流
in对象的类型是InputStream,提供了两个方法
read()方法读取一个字节
read(byte[] b)读取一个字节数组
文件操作类File
File(String pathname):通过将给定路径名字字符串转换为抽象路径来创建一个新的File实例
例:
File path = new File("D:/demo"); //目录对象
File path = new File("D:/demo/text.txt"); //文件对象
File(String parent,String child):根据parent路径名字符串和child路径名字符串创建一个新的File实例
例:
File file = new File("D:/demo","text.txt"); //文件对象
File(URL url):通过将给定的file:URL转换为一个抽象路径名来创建一个新的File实例
例:
File file = new File("file://D:/demo/text.txt");
File(File parent,String child):根据parent抽象路径名和child路径名字符串创建一个新的File实例
例:
File file = new File(path,"text.txt");
判断是目录还是文件
isdirectory() : 是否是目录
isFile() : 是否是文件
检查目录或文件是否存在
exists()
文件搜索类FileFilter与FilenameFilter
boolean accept(File file);
boolean accept(File directory,String name);
按照目录和文件名来进行过滤
关闭
close()
读取文件长度
length()
读取文件 写入文件与读入类似(write)
1:读取一个数据字节
read()
2:读取字节数组
read(byte[] b)
3:灵活读取字节数组
read(byte[] b,int off,int len)
例:
read(b,0,length)
4:读取固定类型的数值
boolean readBoolean()
byte readByte()
char readChar()
double readdouble()
float readFloat()
int readInt()
5:读取一行字符串
readLine()
6:读取中文字符
readUTF()
IO流
输入字节流
抽象类 InputStream
文件类 FileInputStream
过滤类 FilterInputStream
缓存类 BufferedInputStream
输出字节流
抽象类 OutputStream
文件类 FileOutputStream
过滤类 FilterOutputStream
缓存类 BufferedOutputStream
格式化 PrintStream
输入字符流
抽象类 Reader
转换类 InputStreamReader
文件类 FileReader
过滤类 FilterReader
缓存类 BufferedReader
输出字节符
抽象类 Writer
转换类 OutputStreanWriter
文件类 FileWriter
过滤类 FilterWriter
格式化 PrintWriter
常用:
输出流:PrintWriter
输入流:Scanner