提交 6f864ec8 编写于 作者: B Blankj

see 01/17 log

上级 f517ee07
......@@ -4,6 +4,8 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<!--bar-->
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
......
......@@ -9,6 +9,8 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
......@@ -850,7 +852,8 @@ public final class FileUtils {
* @return 文件大小
*/
public static String getFileSize(final String filePath) {
return getFileSize(getFileByPath(filePath));
long len = getFileLength(filePath);
return len == -1 ? "" : byte2FitMemorySize(len);
}
/**
......@@ -903,6 +906,20 @@ public final class FileUtils {
* @return 文件长度
*/
public static long getFileLength(final String filePath) {
boolean isURL = filePath.matches("[a-zA-z]+://[^\\s]*");
if (isURL) {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(filePath).openConnection();
conn.setRequestProperty("Accept-Encoding", "identity");
conn.connect();
if (conn.getResponseCode() == 200) {
return conn.getContentLength();
}
return -1;
} catch (IOException e) {
e.printStackTrace();
}
}
return getFileLength(getFileByPath(filePath));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册