From d594c1daeeb3df250505120fd0310b97b17b5315 Mon Sep 17 00:00:00 2001 From: monster29000 <1067752807@qq.com> Date: Thu, 15 Aug 2024 18:31:04 +0800 Subject: [PATCH] Files.lines is recommended for large files --- .../src/main/java/com/blankj/utilcode/util/ProcessUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ProcessUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ProcessUtils.java index ce78addf57..25bc9f1eb8 100644 --- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ProcessUtils.java +++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ProcessUtils.java @@ -24,12 +24,15 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.nio.file.Files; +import java.nio.file.Paths; import androidx.annotation.NonNull; import androidx.annotation.RequiresPermission; import static android.Manifest.permission.KILL_BACKGROUND_PROCESSES; + /** *
  *     author: Blankj
@@ -221,6 +224,7 @@ public static String getCurrentProcessName() {
     private static String getCurrentProcessNameByFile() {
         try {
             File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
+            //  Use Files.lines(Paths.get(file)), because Files.lines is recommended for large files.
             BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
             String processName = mBufferedReader.readLine().trim();
             mBufferedReader.close();