几个获取文件目录的API
|
1、Context.openFileOutput(string,Context.MODE_PRIVATE); 打开一个文件输出流
//File file = new
File(context.getCacheDir(),"info.dat");//FileOutputStream fos = new
FileOutputStream(file); //上面两句等同于下面这一句代码: FileOutputStream fos = context.openFileOutput("info.dat", Context.MODE_PRIVATE);
|
|
2、Context.openFileInput(string); 打开一个文件输入流
File file = new File(context.getCacheDir(),"info.dat"); FileInputStream fis = new
FileInputStream(file); //FileInputStream fis =
context.openFileInput("info.dat");//和上面两句等同
|
|
3、Context.getCacheDir(); |
获取的目录:/data/data/当前应用程序包名/cache/
context.getCacheDir();//data/data/当前应用程序包名/cache/
4、Context.getFilesDir(); 获取的目录:/data/data/当前包名/files/