當前位置:首頁 » 安卓系統 » android獲取文件大小

android獲取文件大小

發布時間: 2022-08-07 03:17:48

1. android怎麼讀取sql資料庫db文件大小

先簡單說下步驟:
將格式為.db的資料庫文件放到android項目assets目錄中;
在程序必要的時候,將其「拷貝」(文件讀取)到Android 程序默認的資料庫存儲目錄中,一般路徑為「/data/data/項目包名/databases/「;
自定義SQLiteOpenHelper類,創建一個名字跟步驟1中.db名稱一樣的資料庫;
按照平常邏輯,增刪改查資料庫。

2. Android的java怎麼獲取文件大小

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();
}
}
}

3. android如何獲取外部存儲卡的容量

public long getSDAllSize(){ //取得SD卡文件路徑 File path = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(path.getPath()); //獲取單個數據塊的大小(Byte) long blockSize = sf.getBlockSize(); //獲取所有數據塊數 long allBlocks = sf.getBlockCount(); //返回SD卡大小 //return allBlocks * blockSize; //單位Byte //return (allBlocks * blockSize)/1024; //單位KB return (allBlocks * blockSize)/1024/1024; //單位MB }

4. android中如何在下載前獲取下載文件大小

得到文件url,再conn.getContentLength()就可以了

5. Android 如何獲取手機內存大小,內置存儲空間

如果需要清理內存,建議進行以下方法:
1.刪除不必要的數據及應用程序:智能管理器(內存管理器)-儲存空間/內存。
2.關閉不需要的應用程序:點擊屏幕左下角近期任務鍵-點擊要關閉的應用程序右上角的「X」/下方的關閉全部。
3.將多媒體文件移動到擴展卡或將拍攝存儲路徑設置為擴展卡。若未有存儲卡,建議定期將多媒體文件移動到電腦中。
4.卸載不經常使用的軟體或文件。

6. 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;
}

7. android downloadmanager獲取下載文件總大小的時候,為什麼會返回-1。

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Accept-Encoding", "identity");
conn.connect();

加上中間這一行。(默認使用gzip壓縮,導致無法提前獲取下載文件的總大小,不讓它壓縮即可)

8. android為什麼用file.lenght()獲取文件的大小為0

配置文件都是用SharedPreferences寫的吧,存在/data/data/<package name>/shared_prefs目錄下。

9. android怎樣獲取文件的大小

可以用File對象中的length() 方法得到,建一個File對象,指向你的圖片即可。

熱點內容
解壓到當前文件夾右鍵 發布:2024-04-26 03:57:08 瀏覽:979
html5android教程視頻下載 發布:2024-04-26 03:09:59 瀏覽:867
伺服器的描述是什麼 發布:2024-04-26 03:08:32 瀏覽:394
個人加密 發布:2024-04-26 03:01:23 瀏覽:521
linuxusbgadget 發布:2024-04-26 02:52:54 瀏覽:304
我的世界空島世界伺服器地址 發布:2024-04-26 01:39:08 瀏覽:248
尼爾機械紀元加密 發布:2024-04-26 01:37:11 瀏覽:868
在控制台輸出sql語句 發布:2024-04-26 01:08:12 瀏覽:432
動畫java 發布:2024-04-26 01:02:40 瀏覽:12
得力文件夾5302 發布:2024-04-26 00:21:32 瀏覽:91