getCacheDir()和getFilesDir()方法區別.


Activity提供了getCacheDir()和getFilesDir()方法:

getCacheDir()方法用於獲取/data/data//cache目錄

getFilesDir()方法用於獲取/data/data//files目錄

//==================================================

將文件寫入SD卡內:

獲取SDCard的狀態:

Environment.getExtemalStorageState()

Environment.MEDIA_MOUNTED手機裝有SDCard,並且可以進行讀寫

獲取SDCard的目錄:Environment.getExtemalStorageDirectory()

//=============================================

File saveFile=new File("/sdcard/zhzhg.txt");

或:File sdCardDir=new File("/sdcard");//獲取SD卡目錄

File saveFile = new File(sdCardDir,"zhzhg.txt");

FileOutputStream outStream = new FileOutputStream(saveFile);

outStream.write("文件的讀寫".getBytes());

outStream.close();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM