本文整理了Java中cn.hutool.core.io.FileUtil.getReader()
方法的一些代码示例,展示了FileUtil.getReader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getReader()
方法的具体详情如下:
包路径:cn.hutool.core.io.FileUtil
类名称:FileUtil
方法名:getReader
[英]获得一个文件读取器
[中]获得一个文件读取器
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 文件Path
* @return BufferedReader对象
* @throws IORuntimeException IO异常
* @since 4.0.0
*/
public static BufferedReader getUtf8Reader(Path path) throws IORuntimeException {
return getReader(path, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 文件Path
* @return BufferedReader对象
* @throws IORuntimeException IO异常
* @since 4.0.0
*/
public static BufferedReader getUtf8Reader(Path path) throws IORuntimeException {
return getReader(path, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 文件路径
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getUtf8Reader(String path) throws IORuntimeException {
return getReader(path, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param file 文件
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getUtf8Reader(File file) throws IORuntimeException {
return getReader(file, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param file 文件
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getUtf8Reader(File file) throws IORuntimeException {
return getReader(file, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 文件路径
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getUtf8Reader(String path) throws IORuntimeException {
return getReader(path, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 绝对路径
* @param charset 字符集
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getReader(String path, Charset charset) throws IORuntimeException {
return getReader(file(path), charset);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 绝对路径
* @param charsetName 字符集
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getReader(String path, String charsetName) throws IORuntimeException {
return getReader(file(path), charsetName);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 绝对路径
* @param charsetName 字符集
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getReader(String path, String charsetName) throws IORuntimeException {
return getReader(file(path), charsetName);
}
代码示例来源:origin: looly/hutool
/**
* 获得一个文件读取器
*
* @param path 绝对路径
* @param charset 字符集
* @return BufferedReader对象
* @throws IORuntimeException IO异常
*/
public static BufferedReader getReader(String path, Charset charset) throws IORuntimeException {
return getReader(file(path), charset);
}
代码示例来源:origin: looly/hutool
/**
* 按照行处理文件内容
*
* @param lineHandler 行处理器
* @throws IORuntimeException IO异常
* @since 3.0.9
*/
public void readLines(LineHandler lineHandler) throws IORuntimeException{
BufferedReader reader = null;
try {
reader = FileUtil.getReader(file, charset);
IoUtil.readLines(reader, lineHandler);
} finally {
IoUtil.close(reader);
}
}
代码示例来源:origin: looly/hutool
/**
* 按照行处理文件内容
*
* @param lineHandler 行处理器
* @throws IORuntimeException IO异常
* @since 3.0.9
*/
public void readLines(LineHandler lineHandler) throws IORuntimeException{
BufferedReader reader = null;
try {
reader = FileUtil.getReader(file, charset);
IoUtil.readLines(reader, lineHandler);
} finally {
IoUtil.close(reader);
}
}
代码示例来源:origin: looly/hutool
/**
* 通过文件初始化过滤器.
*
* @param path 文件路径
* @param charset 字符集
* @throws IOException IO异常
*/
public void init(String path, String charset) throws IOException {
BufferedReader reader = FileUtil.getReader(path, charset);
try {
String line;
while(true) {
line = reader.readLine();
if(line == null) {
break;
}
this.add(line);
}
}finally {
IoUtil.close(reader);
}
}
代码示例来源:origin: looly/hutool
/**
* 从文件中读取每一行数据
*
* @param <T> 集合类型
* @param collection 集合
* @return 文件中的每行内容的集合
* @throws IORuntimeException IO异常
*/
public <T extends Collection<String>> T readLines(T collection) throws IORuntimeException {
BufferedReader reader = null;
try {
reader = FileUtil.getReader(file, charset);
String line;
while (true) {
line = reader.readLine();
if (line == null) {
break;
}
collection.add(line);
}
return collection;
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(reader);
}
}
代码示例来源:origin: looly/hutool
/**
* 通过文件初始化过滤器.
*
* @param path 文件路径
* @param charset 字符集
* @throws IOException IO异常
*/
public void init(String path, String charset) throws IOException {
BufferedReader reader = FileUtil.getReader(path, charset);
try {
String line;
while(true) {
line = reader.readLine();
if(line == null) {
break;
}
this.add(line);
}
}finally {
IoUtil.close(reader);
}
}
代码示例来源:origin: looly/hutool
/**
* 从文件中读取每一行数据
*
* @param <T> 集合类型
* @param collection 集合
* @return 文件中的每行内容的集合
* @throws IORuntimeException IO异常
*/
public <T extends Collection<String>> T readLines(T collection) throws IORuntimeException {
BufferedReader reader = null;
try {
reader = FileUtil.getReader(file, charset);
String line;
while (true) {
line = reader.readLine();
if (line == null) {
break;
}
collection.add(line);
}
return collection;
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(reader);
}
}
代码示例来源:origin: looly/hutool
/**
* 读取CSV文件
*
* @param path CSV文件
* @param charset 文件编码,默认系统编码
* @return {@link CsvData},包含数据列表和行信息
* @throws IORuntimeException IO异常
*/
public CsvData read(Path path, Charset charset) throws IORuntimeException {
Assert.notNull(path, "path must not be null");
try (Reader reader = FileUtil.getReader(path, charset)) {
return read(reader);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
代码示例来源:origin: looly/hutool
/**
* 读取CSV文件
*
* @param path CSV文件
* @param charset 文件编码,默认系统编码
* @return {@link CsvData},包含数据列表和行信息
* @throws IORuntimeException IO异常
*/
public CsvData read(Path path, Charset charset) throws IORuntimeException {
Assert.notNull(path, "path must not be null");
try (Reader reader = FileUtil.getReader(path, charset)) {
return read(reader);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
代码示例来源:origin: looly/hutool
/**
* 按照给定的readerHandler读取文件中的数据
*
* @param <T> 读取的结果对象类型
* @param readerHandler Reader处理类
* @return 从文件中read出的数据
* @throws IORuntimeException IO异常
*/
public <T> T read(ReaderHandler<T> readerHandler) throws IORuntimeException {
BufferedReader reader = null;
T result = null;
try {
reader = FileUtil.getReader(this.file, charset);
result = readerHandler.handle(reader);
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(reader);
}
return result;
}
代码示例来源:origin: looly/hutool
/**
* 按照给定的readerHandler读取文件中的数据
*
* @param <T> 读取的结果对象类型
* @param readerHandler Reader处理类
* @return 从文件中read出的数据
* @throws IORuntimeException IO异常
*/
public <T> T read(ReaderHandler<T> readerHandler) throws IORuntimeException {
BufferedReader reader = null;
T result = null;
try {
reader = FileUtil.getReader(this.file, charset);
result = readerHandler.handle(reader);
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(reader);
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!