Android中關於內部儲存的一些重要函式
public abstract File getCacheDir ()
Returns the absolute path to the application specific cache directory on the filesystem. These files will be ones that get deleted first when the device runs low on storage. There is no guarantee when these files will be deleted. Note: you should not rely on the system deleting these files for you; you should always have a reasonable maximum, such as 1 MB, for the amount of space you consume with cache files, and prune those files when exceeding that space.
該目錄主要用於存放快取檔案,當系統的記憶體儲存空間緊張時,該目錄下的檔案會被刪除掉。關於這些檔案究竟會在儲存空間剩餘多少的情況,沒有嚴格的標準保障。
注意:你不應該依賴系統來清理這些快取檔案,你應該對這些快取檔案佔用的最大儲存空間設定個最大值,比如是1M,當實際佔用空間超過這個值時,你應該對這些快取檔案做相應的清理工作(prune)。
Returns
- Returns the path of the directory holding application cache files.
See Also
-
openFileOutput(String, int)
-
getFileStreamPath(String)
-
getDir(String, int)
- 示例1
- import android.app.Activity;
- import android.content.Context;
- import android.os.Bundle;
- import android.util.Log;
- public class MainActivity extends Activity {
- final static String TAG="robin";
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Context context=this;
- String path=context.getCacheDir().getAbsolutePath();
- Log.i(TAG,"path:"+path);
- }
- }
- 執行結果
- 10-01 14:57:52.296: I/robin(7835): path:/data/data/com.lenovo/cache
public abstract File getDir (String name, int mode)
Retrieve, creating if needed, a new directory in which the application can place its own custom data files. You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.
該函式主要用於得到一個資料夾的控制程式碼,並通過該控制程式碼建立和訪問外資料夾。
注意:引數int mode是指資料夾的訪問許可權而並不包括其子資料夾和檔案的訪問許可權
Parameters
name | Name of the directory to retrieve. This is a directory that is created as part of your application data. |
---|---|
mode |
Operating mode. Use 0 or MODE_PRIVATE for
the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to
control permissions. |
Returns
- Returns a File object for the requested directory. The directory will have been created if it does not already exist.
See Also
-
openFileOutput(String, int)
- 示例2
- File file=context.getDir("download", Context.MODE_PRIVATE);
- String path=file.getAbsolutePath();
- Log.i(TAG,"path:"+path);
- 執行結果
- 10-02 08:56:49.278: I/robin(12055): path:/data/data/com.lenovo/app_download
public abstract File getFileStreamPath (String name)
Returns the absolute path on the filesystem where a file created with openFileOutput(String,
int)
is stored.
See Also
-
openFileOutput(String, int)
-
getFilesDir()
-
getDir(String, int)
- 示例3
- File file=context.getFileStreamPath("download");
- String path=file.getAbsolutePath();
- Log.i(TAG,"path:"+path);
- 執行結果
- 10-02 09:17:55.913: I/robin(12507): path:/data/data/com.lenovo/files/download
public abstract File getFilesDir ()
Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String,
int)
are stored.
public abstract FileInputStream openFileInput (String name)
Open a private file associated with this Context's application package for reading.
Throws
FileNotFoundException |
---|
public abstract FileOutputStream openFileOutput (String name, int mode)
Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.
Parameters
name | The name of the file to open; can not contain path separators. |
---|---|
mode | Operating mode. Use 0 or MODE_PRIVATE for
the default operation, MODE_APPEND to
append to an existing file, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to
control permissions. |
Throws
FileNotFoundException |
---|
public abstract boolean deleteFile (String name)
Delete the given private file associated with this Context's application package.
public abstract String[] fileList ()
Returns an array of strings naming the private files associated with this Context's application package.
public static File getDataDirectory ()
Gets the Android data directory.
用File返回資料檔案的根目錄,返回的檔案的路徑為“/data”。該目錄下的檔案是隻讀。應用程式無法對該目錄下的檔案進行寫操作。
public static File getDownloadCacheDirectory ()
Gets the Android Download/Cache content directory.
用File返回快取檔案的根目錄,返回的檔案的路徑為“/cache”。對於第三方應用程式。該目錄下的檔案是隻讀。第三方應用程式無法對該目錄下的檔案進行寫操作。
public static File getRootDirectory ()
Gets the Android root directory.
用File返回Android系統檔案的根目錄,返回的檔案的路徑為“/system”。該目錄下的檔案是隻讀。應用程式無法對該目錄下的檔案進行寫操作。
相關文章
- Android中關於外部儲存的一些重要函式Android函式
- Android-內部儲存和外部儲存Android
- oracle中dump函式及oracle NUMBER型別內部儲存機制Oracle函式型別
- Android內部儲存和外部儲存,以及讀取Android讀取RAM,ROM內部儲存和外部儲存卡容量Android
- 關於ORACLE組合索引內部儲存淺談Oracle索引
- 關於變數的宣告和定義、內部函式和外部函式變數函式
- mysql儲存函過程和儲存函式都屬於儲存程式MySql儲存函式
- 關於儲存及CSS的一些技巧CSS
- 儲存函式儲存函式
- 函式索引的儲存函式索引
- 關於oracle內建函式的使用Oracle函式
- 幾個重要的內建函式函式
- Mysql 的儲存過程和儲存函式MySql儲存過程儲存函式
- 儲存過程與儲存函式儲存過程儲存函式
- 結構體內部儲存中的對齊問題結構體
- 關於 Math.random 的一些函式random函式
- 關於虛擬函式的一些理解函式
- 關於儲存及RAC的一些好文章
- 數值在Oracle的內部儲存Oracle
- PL/SQL 中的儲存過程與函式SQL儲存過程函式
- Oracle中關於函式的使用Oracle函式
- 關於qt中的tr()函式QT函式
- SQL SERVER 關於檔案儲存一些方法SQLServer
- 匿名內部類中關於new Runnable ( )
- MongoDB 儲存引擎與內部原理MongoDB儲存引擎
- mysql練習 —— 關於一些函式的使用MySql函式
- 如何在函式內部定義函式?函式
- 函式內部This的指向問題函式
- 函式內部的變數提升函式變數
- Cassandra的內部資料儲存結構
- SQL中儲存過程和函式的區別SQL儲存過程函式
- 儲存過程 函式儲存過程函式
- SQL---------儲存函式SQL儲存函式
- (Oracle)儲存過程、儲存函式和包的相關知識與例項Oracle儲存過程儲存函式
- mysql和orcale的儲存過程和儲存函式MySql儲存過程儲存函式
- 關於cuda中的函式問題函式
- 關於字元函式的一些應用總結字元函式
- python中關於列表的一些內建方法(函式)和操作(部分需要理解的會給出例子)Python函式