Skip to content

Commit 481f98c

Browse files
committed
see 12/13 log
1 parent 1dfcade commit 481f98c

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

README-CN.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,12 @@ listFilesInDirWithFilter : 获取目录下所有符合filter的文件包
190190
searchFileInDir : 获取目录下指定文件名的文件包括子目录
191191
writeFileFromIS : 将输入流写入文件
192192
writeFileFromString : 将字符串写入文件
193+
readFile2List : 指定编码按行读取文件到链表中
194+
readFile2String : 指定编码按行读取文件到字符串中
195+
readFile2Bytes : 读取文件到字符数组中
196+
getFileLastModified : 获取文件最后修改的毫秒时间戳
193197
getFileCharsetSimple : 简单获取文件编码格式
194198
getFileLines : 获取文件行数
195-
readFile2List : 指定编码按行读取文件到List
196-
readFile2SB : 指定编码按行读取文件到StringBuilder中
197199
getDirSize : 获取目录大小
198200
getFileSize : 获取文件大小
199201
getDirLength : 获取目录长度

utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public static boolean isAppForeground(Context context) {
495495
* @return {@code true}: 是<br>{@code false}: 否
496496
*/
497497
public static boolean isAppForeground(Context context, String packageName) {
498-
return !StringUtils.isSpace(packageName) && packageName.equals(ProcessUtils.getForegroundProcessName(context));
498+
return !StringUtils.isSpace(packageName) && packageName.equals(ProcessUtils.getForegroundProcessName());
499499
}
500500

501501
/**

utilcode/src/main/java/com/blankj/utilcode/utils/BarUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* </pre>
2828
*/
2929
public class BarUtils {
30+
3031
private BarUtils() {
3132
throw new UnsupportedOperationException("u can't instantiate me...");
3233
}

utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public static boolean writeFileFromString(File file, String content, boolean app
801801
}
802802

803803
/**
804-
* 指定编码按行读取文件到List
804+
* 指定编码按行读取文件到链表中
805805
*
806806
* @param filePath 文件路径
807807
* @param charsetName 编码格式
@@ -812,7 +812,7 @@ public static List<String> readFile2List(String filePath, String charsetName) {
812812
}
813813

814814
/**
815-
* 指定编码按行读取文件到List
815+
* 指定编码按行读取文件到链表中
816816
*
817817
* @param file 文件
818818
* @param charsetName 编码格式
@@ -823,7 +823,7 @@ public static List<String> readFile2List(File file, String charsetName) {
823823
}
824824

825825
/**
826-
* 指定编码按行读取文件到List
826+
* 指定编码按行读取文件到链表中
827827
*
828828
* @param filePath 文件路径
829829
* @param st 需要读取的开始行数
@@ -837,7 +837,7 @@ public static List<String> readFile2List(String filePath, int st, int end, Strin
837837
}
838838

839839
/**
840-
* 指定编码按行读取文件到List
840+
* 指定编码按行读取文件到链表中
841841
*
842842
* @param file 文件
843843
* @param st 需要读取的开始行数
@@ -940,6 +940,27 @@ public static byte[] readFile2Bytes(File file) {
940940
}
941941
}
942942

943+
/**
944+
* 获取文件最后修改的毫秒时间戳
945+
*
946+
* @param filePath 文件路径
947+
* @return 文件最后修改的毫秒时间戳
948+
*/
949+
public static long getFileLastModified(String filePath) {
950+
return getFileLastModified(getFileByPath(filePath));
951+
}
952+
953+
/**
954+
* 获取文件最后修改的毫秒时间戳
955+
*
956+
* @param file 文件
957+
* @return 文件最后修改的毫秒时间戳
958+
*/
959+
public static long getFileLastModified(File file) {
960+
if (file == null) return -1;
961+
return file.lastModified();
962+
}
963+
943964
/**
944965
* 简单获取文件编码格式
945966
*

utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ public void testGetFileLines() throws Exception {
174174
assertThat(getFileLines(path + "UTF8.txt")).isEqualTo(7);
175175
}
176176

177+
@Test
178+
public void testGetFileLastModified()throws Exception{
179+
System.out.println(TimeUtils.millis2String(getFileLastModified(path)));
180+
}
181+
177182
@Test
178183
public void testReadFile2List() throws Exception {
179184
System.out.println(readFile2List(path + "UTF8.txt", "").toString());

0 commit comments

Comments
 (0)