Android系统会为每个应用分配的私有目录,只有该应用本身可以访问。在内部存储空间中保存的文件不会被系统清理掉,除非用户卸载该应用。
在Android中,可以使用Context.getFilesDir0方法获取内部存储空间的路径。下面是一个示例代码:
//获欺内部存储空间的路轻
File filesDir = context.getFilesDir();
String filePath = filesDir.getAbsolutePath()+"/config.txt";
//保存配置文件
try{
FileWriter writer = new FileWriter(filePath);
writer.write("Hello World!");
writer.close();
}catch (IOException e){
e.printStackTrace();
}
//读取配置文件
try{
FileReader reader = new FileReader(filePath);
char[] buffer = new char[1024];
reader.read(buffer);
reader.close();
String content = new String(buffer);
Log.d(TAG,"Content:"+content);
}catch (IOException e) {
e.printStackTrace();
}