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();
时间: 2024-10-23 10:53:23