public class FileReader extends FileWrapper
| Modifier and Type | Class and Description |
|---|---|
static interface |
FileReader.ReaderHandler<T>
Reader处理接口
|
charset, DEFAULT_CHARSET, file| Constructor and Description |
|---|
FileReader(File file)
构造
编码使用 FileWrapper.DEFAULT_CHARSET |
FileReader(File file,
Charset charset)
构造
|
FileReader(File file,
String charset)
构造
|
FileReader(String filePath)
构造
编码使用 FileWrapper.DEFAULT_CHARSET |
FileReader(String filePath,
Charset charset)
构造
|
FileReader(String filePath,
String charset)
构造
|
| Modifier and Type | Method and Description |
|---|---|
static FileReader |
create(File file)
创建 FileReader, 编码:
FileWrapper.DEFAULT_CHARSET |
static FileReader |
create(File file,
Charset charset)
创建 FileReader
|
BufferedInputStream |
getInputStream()
获得输入流
|
BufferedReader |
getReader()
获得一个文件读取器
|
<T> T |
read(FileReader.ReaderHandler<T> readerHandler)
按照给定的readerHandler读取文件中的数据
|
byte[] |
readBytes()
读取文件所有数据
文件的长度不能超过 Integer.MAX_VALUE |
List<String> |
readLines()
从文件中读取每一行数据
|
void |
readLines(LineHandler lineHandler)
按照行处理文件内容
|
<T extends Collection<String>> |
readLines(T collection)
从文件中读取每一行数据
|
String |
readString()
读取文件内容
|
long |
writeToStream(OutputStream out)
将文件写入流中,此方法不会关闭比输出流
|
long |
writeToStream(OutputStream out,
boolean isCloseOut)
将文件写入流中
|
getCharset, getFile, readableFileSize, setCharset, setFilepublic FileReader(File file, Charset charset)
file - 文件charset - 编码,使用 CharsetUtilpublic FileReader(File file, String charset)
file - 文件charset - 编码,使用 CharsetUtil.charset(String)public FileReader(String filePath, Charset charset)
filePath - 文件路径,相对路径会被转换为相对于ClassPath的路径charset - 编码,使用 CharsetUtilpublic FileReader(String filePath, String charset)
filePath - 文件路径,相对路径会被转换为相对于ClassPath的路径charset - 编码,使用 CharsetUtil.charset(String)public FileReader(File file)
FileWrapper.DEFAULT_CHARSETfile - 文件public FileReader(String filePath)
FileWrapper.DEFAULT_CHARSETfilePath - 文件路径,相对路径会被转换为相对于ClassPath的路径public static FileReader create(File file, Charset charset)
file - 文件charset - 编码,使用 CharsetUtilpublic static FileReader create(File file)
FileWrapper.DEFAULT_CHARSETfile - 文件public byte[] readBytes()
throws IORuntimeException
Integer.MAX_VALUEIORuntimeException - IO异常public String readString() throws IORuntimeException
IORuntimeException - IO异常public <T extends Collection<String>> T readLines(T collection) throws IORuntimeException
T - 集合类型collection - 集合IORuntimeException - IO异常public void readLines(LineHandler lineHandler) throws IORuntimeException
lineHandler - 行处理器IORuntimeException - IO异常public List<String> readLines() throws IORuntimeException
IORuntimeException - IO异常public <T> T read(FileReader.ReaderHandler<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.