Skip to content

Commit 6f864ec

Browse files
committed
see 01/17 log
1 parent f517ee0 commit 6f864ec

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
66

7+
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
8+
79
<!--bar-->
810
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
911

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.io.FileNotFoundException;
1010
import java.io.IOException;
1111
import java.io.InputStream;
12+
import java.net.HttpURLConnection;
13+
import java.net.URL;
1214
import java.security.DigestInputStream;
1315
import java.security.MessageDigest;
1416
import java.security.NoSuchAlgorithmException;
@@ -850,7 +852,8 @@ public static String getDirSize(final File dir) {
850852
* @return 文件大小
851853
*/
852854
public static String getFileSize(final String filePath) {
853-
return getFileSize(getFileByPath(filePath));
855+
long len = getFileLength(filePath);
856+
return len == -1 ? "" : byte2FitMemorySize(len);
854857
}
855858

856859
/**
@@ -903,6 +906,20 @@ public static long getDirLength(final File dir) {
903906
* @return 文件长度
904907
*/
905908
public static long getFileLength(final String filePath) {
909+
boolean isURL = filePath.matches("[a-zA-z]+://[^\\s]*");
910+
if (isURL) {
911+
try {
912+
HttpURLConnection conn = (HttpURLConnection) new URL(filePath).openConnection();
913+
conn.setRequestProperty("Accept-Encoding", "identity");
914+
conn.connect();
915+
if (conn.getResponseCode() == 200) {
916+
return conn.getContentLength();
917+
}
918+
return -1;
919+
} catch (IOException e) {
920+
e.printStackTrace();
921+
}
922+
}
906923
return getFileLength(getFileByPath(filePath));
907924
}
908925

0 commit comments

Comments
 (0)