public class FileReader extends FileWrapper
charset, DEFAULT_CHARSET, file
Constructor and Description |
---|
FileReader(File file,
Charset charset)
构造
|
Modifier and Type | Method and Description |
---|---|
BufferedInputStream |
getInputStream()
获得输入流
|
BufferedReader |
getReader()
获得一个文件读取器
|
static FileReader |
of(File file)
创建 FileReader, 编码:
FileWrapper.DEFAULT_CHARSET |
static FileReader |
of(File file,
Charset charset)
创建 FileReader
|
<T> T |
read(SerFunction<BufferedReader,T> readerHandler)
按照给定的readerHandler读取文件中的数据
|
byte[] |
readBytes()
读取文件所有数据
文件的长度不能超过 Integer.MAX_VALUE |
List<String> |
readLines()
从文件中读取每一行数据
|
void |
readLines(SerConsumer<String> lineHandler)
按照行处理文件内容
|
<T extends Collection<String>> |
readLines(T collection)
从文件中读取每一行数据
|
<T extends Collection<String>> |
readLines(T collection,
Predicate<String> predicate)
从文件中读取每一行数据
|
String |
readString()
读取文件内容
|
long |
writeToStream(OutputStream out)
将文件写入流中,此方法不会关闭比输出流
|
long |
writeToStream(OutputStream out,
boolean isCloseOut)
将文件写入流中
|
getCharset, getRaw, readableFileSize, setCharset, setFile
public FileReader(File file, Charset charset)
file
- 文件charset
- 编码,使用 CharsetUtil
public static FileReader of(File file, Charset charset)
file
- 文件charset
- 编码,使用 CharsetUtil
public static FileReader of(File file)
FileWrapper.DEFAULT_CHARSET
file
- 文件public byte[] readBytes() throws IORuntimeException
Integer.MAX_VALUE
IORuntimeException
- IO异常public String readString() throws IORuntimeException
IORuntimeException
- IO异常public <T extends Collection<String>> T readLines(T collection) throws IORuntimeException
T
- 集合类型collection
- 集合IORuntimeException
- IO异常public <T extends Collection<String>> T readLines(T collection, Predicate<String> predicate) throws IORuntimeException
T
- 集合类型collection
- 集合predicate
- 断言,断言为真的加入到提供的集合中IORuntimeException
- IO异常public void readLines(SerConsumer<String> lineHandler) throws IORuntimeException
lineHandler
- 行处理器IORuntimeException
- IO异常public List<String> readLines() throws IORuntimeException
IORuntimeException
- IO异常public <T> T read(SerFunction<BufferedReader,T> readerHandler) throws IORuntimeException
T
- 读取的结果对象类型readerHandler
- Reader处理类IORuntimeException
- IO异常public BufferedReader getReader() throws IORuntimeException
IORuntimeException
- IO异常public BufferedInputStream getInputStream() throws IORuntimeException
IORuntimeException
- IO异常public long writeToStream(OutputStream out) throws IORuntimeException
out
- 流IORuntimeException
- IO异常public long writeToStream(OutputStream out, boolean isCloseOut) throws IORuntimeException
out
- 流isCloseOut
- 是否关闭输出流IORuntimeException
- IO异常Copyright © 2025. All rights reserved.