客官,小板凳坐好,开始啦!
FileReader
的构造方法和FileInputStream
很相似,都是传入文件路径或者文件对象又或者是文件描述符。
根据继承图以及方法,来过一下常用的API吧!
- public String getEncoding() 返回编码名称
public class Test {
public static void main(String[] args) {
try (FileReader fileReader = new FileReader(filePath)) {
System.out.println("Encoding: " + fileReader.getEncoding());
} catch (Exception exception) {
System.out.println("发生异常");
}
}
}
Encoding: UTF8
- public boolean markSupported()
与FileInputStream
很相似也是不支持mark
的,看下源码:
public boolean markSupported() {
return false;
}
那mark
和reset
方法也就不说了,不支持嘛!
- public long skip(long n) throws IOException 跳过字符数,和
FileInputStream
很相似!
public class Test {
public static void main(String[] args) {
try (FileReader fileReader