mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
801ce05f1a
commit
4e3f2153c5
@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.7.22 (2022-02-21)
|
# 5.7.22 (2022-02-22)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【poi 】 ExcelUtil.readBySax增加对POI-5.2.0的兼容性(issue#I4TJF4@gitee)
|
* 【poi 】 ExcelUtil.readBySax增加对POI-5.2.0的兼容性(issue#I4TJF4@gitee)
|
||||||
@ -11,6 +11,7 @@
|
|||||||
* 【json 】 新增TemporalAccessorSerializer
|
* 【json 】 新增TemporalAccessorSerializer
|
||||||
* 【core 】 使多个xxxBuilder实现Builder接口,扩展CheckedUtil(pr#545@Gitee)
|
* 【core 】 使多个xxxBuilder实现Builder接口,扩展CheckedUtil(pr#545@Gitee)
|
||||||
* 【core 】 CheckedUtil删除第二个参数为RuntimeException的方法
|
* 【core 】 CheckedUtil删除第二个参数为RuntimeException的方法
|
||||||
|
* 【core 】 FileUtil增加getTotalLines方法
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【cache 】 修复ReentrantCache.toString方法线程不安全问题(issue#2140@Github)
|
* 【cache 】 修复ReentrantCache.toString方法线程不安全问题(issue#2140@Github)
|
||||||
|
@ -22,12 +22,31 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.core.util.URLUtil;
|
import cn.hutool.core.util.URLUtil;
|
||||||
import cn.hutool.core.util.ZipUtil;
|
import cn.hutool.core.util.ZipUtil;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.LineNumberReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.io.Reader;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.*;
|
import java.nio.file.DirectoryNotEmptyException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -554,23 +573,22 @@ public class FileUtil extends PathUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算文件的总行数
|
* 计算文件的总行数<br>
|
||||||
|
* 读取文件采用系统默认编码,一般乱码不会造成行数错误。
|
||||||
*
|
*
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
* @return 该文件总行数
|
* @return 该文件总行数
|
||||||
|
* @since 5.7.22
|
||||||
*/
|
*/
|
||||||
public static int getTotalLines(File file) {
|
public static int getTotalLines(File file) {
|
||||||
if (!isFile(file)) {
|
if (false == isFile(file)) {
|
||||||
throw new IORuntimeException("input must be file");
|
throw new IORuntimeException("Input must be a File");
|
||||||
}
|
}
|
||||||
|
try (final LineNumberReader lineNumberReader = new LineNumberReader(new java.io.FileReader(file))) {
|
||||||
try (
|
|
||||||
final BufferedReader reader = getReader(file, CharsetUtil.CHARSET_UTF_8);
|
|
||||||
final LineNumberReader lineNumberReader = new LineNumberReader(reader)
|
|
||||||
) {
|
|
||||||
// 设置起始为1
|
// 设置起始为1
|
||||||
lineNumberReader.setLineNumber(1);
|
lineNumberReader.setLineNumber(1);
|
||||||
// 跳过文件中内容
|
// 跳过文件中内容
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
lineNumberReader.skip(Long.MAX_VALUE);
|
lineNumberReader.skip(Long.MAX_VALUE);
|
||||||
// 获取当前行号
|
// 获取当前行号
|
||||||
return lineNumberReader.getLineNumber();
|
return lineNumberReader.getLineNumber();
|
||||||
|
@ -63,6 +63,7 @@ public class RestTest {
|
|||||||
.body(JSONUtil.createObj()
|
.body(JSONUtil.createObj()
|
||||||
.set("advertiser_ids", new Long[] {1690657248243790L})
|
.set("advertiser_ids", new Long[] {1690657248243790L})
|
||||||
.set("fields", new String[] {"id", "name", "status"}).toString());
|
.set("fields", new String[] {"id", "name", "status"}).toString());
|
||||||
|
Console.log(request);
|
||||||
Console.log(request.execute().body());
|
Console.log(request.execute().body());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user