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绠$悊鍣ㄥ備綍鏌ョ湅鏂囦欢澶圭殑澶у皬锛
闀挎寜鏂囦欢澶癸紝鍦ㄥ脊鍑烘潵鐨勮彍鍗曚腑鐐光滃睘鎬р
瑕佹槸涓嶈屽啀閲嶆柊瀹夎呬竴閬嶈瘯璇曞憿