android中的java獲取文件大小的方法:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
public class FileContent {
private String path = "F:\\下載說明.txt";
public FileContent() throws IOException
{
File f = new File(path);
FileReader fileReader = new FileReader(f);
BufferedReader br = new BufferedReader(fileReader);
String str;
while((str = br.readLine() ) != null)
{
System.out.println(str);
}
System.out.println(new FileInputStream(new File(path)).available() / 1024 / 1024 +"M");
}
public static void main(String[] args) {
try {
new FileContent();
} catch (IOException e) {
e.printStackTrace();
}
}
}
B. Android 11.0灝嗗彇娑堝崟鏂囦歡4GB澶у皬闄愬埗鍚楋紵
Android 11鎴栧皢甯︽潵鏄捐憲闈╂柊錛氬憡鍒鍗曟枃浠4GB闄愬埗灝界″綋鍓岮ndroid鎵嬫満鏅閬嶆嫢鏈夊ぇ瀹歸噺瀛樺偍錛屼絾鍦ㄦ枃浠剁$悊涓婏紝4GB鐨勯檺鍒朵粛鐒跺瓨鍦ㄣ傛嵁XDA璁哄潧閫忛湶錛岃胺姝屾h″垝鍦ˋndroid 11.0鐗堟湰涓瀹炴柦涓欏歸噸澶у彉闈╋紝鍗沖彇娑堣繖涓緇忓吀闄愬埗錛屼互閫傚簲鏇撮珮娓呰嗛戠殑闇奼傘
Android 11.0鐨勫紑鍙戜腑錛屽凡嫻嬭瘯浜32GB鐨勮嗛戝綍鍒訛紝鐢氳嚦灝濊瘯榪囧瓨鍌ㄦ弧鎵嬫満瀛樺偍鐨勫綍闊籌紝榪欒〃鏄庤胺姝屾e湪瀵瑰獟浣撶被鍔熻兘榪涜屽崌綰э紝鐩鏍囨槸娑堥櫎32浣嶆枃浠跺ぇ灝忕殑闄愬埗錛岃繖灝嗙洿鎺ュ獎鍝嶅埌4K瑙嗛戠殑澶勭悊鏂瑰紡銆
鐩鍓嶏紝4K瑙嗛戝綍鍒12鍒嗛挓宸﹀彸錛屾枃浠跺ぇ灝忓嵆閫艱繎4GB錛岀浉鏈哄簲鐢ㄤ細鑷鍔ㄥ皢瑙嗛戞媶鍒嗘垚澶氫釜鏂囦歡錛岃繖緇欑敤鎴峰甫鏉ヤ笉渚褲傚傛灉Android 11.0鍙栨秷鍗曟枃浠4GB闄愬埗錛岀敤鎴峰皢鑳芥洿嫻佺晠鍦板綍鍒跺拰綆$悊瑙嗛戱紝灝ゅ叾鏄瀵逛簬鏈鏉ュ彲鑳界殑1TB瀛樺偍鎵嬫満鍜8K瑙嗛戠殑鏅鍙娿
棰勮¤繖欏規敼鍔ㄤ細鍦2020騫3鏈堢殑Android 11嫻嬭瘯鐗堜腑瀹炵幇錛岃繖灝嗕嬌寰桝ndroid緋葷粺鏇村ソ鍦伴傚簲鏈鏉ラ珮娓呰嗛戝唴瀹圭殑闇奼傦紝SD鍗$殑浣跨敤棰戠巼鍙鑳戒細榪涗竴姝ヤ笅闄嶏紝涓虹敤鎴峰甫鏉ユ洿鍔犱究鎹風殑浣撻獙銆
C. android如何獲取assets文件夾下面文件的大小
我覺得按行讀取進度必定不準確,還是改成用流來讀取;用 progressBar來實現進度現實就可以了。
D. android 如何獲得網路文件大小
public long getFileSize(String urlString) throws IOException,Exception{
long lenght = 0;
String url = UrlEncode(urlString, "UTF-8");
//URL mUrl = new URL(urlString);
URL mUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) mUrl.openConnection();
conn.setConnectTimeout(5*1000);
conn.setRequestMethod("GET");
conn .setRequestProperty("Accept-Encoding", "identity");
conn.setRequestProperty("Referer", url);
//conn.setRequestProperty("Referer", urlString);
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.connect();
int responseCode = conn.getResponseCode();
// 判斷請求是否成功處理
if (responseCode == HttpStatus.SC_OK) {
lenght = conn.getContentLength();
}
return lenght;
}
E. ANDROID鐨別s綆$悊鍣ㄥ備綍鏌ョ湅鏂囦歡澶圭殑澶у皬錛
闀挎寜鏂囦歡澶癸紝鍦ㄥ脊鍑烘潵鐨勮彍鍗曚腑鐐光滃睘鎬р
瑕佹槸涓嶈屽啀閲嶆柊瀹夎呬竴閬嶈瘯璇曞憿