我使用下面的代码写入文件写入缓存文件:读以前由相同的应用程序
File file = new File(getCacheDir(), "cachefile");
FileOutputStream fos = new FileOutputStream(file);
StringBuilder cachetext = new StringBuilder();
Iterator bri = brands.iterator();
Iterator bli = brand_id.iterator();
while(bli.hasNext()) {
cachetext.append(bli.next() + "|" + bri.next() + System.getProperty("line.separator"));
}
fos.write(cachetext.toString().getBytes());
fos.close();
这工作得很好 - 没有错误和文件结束了含有什么,我希望它包含。当我去通过openFileInput()读取它,但是,我得到一个异常告诉我,路径分隔符不允许
FileInputStream fis = openFileInput(getCacheDir() + "/cachefile");
不够公平,它包含一个斜杠,但我还能怎么指定的路径我想打开的文件?当然,必须有办法做到这一点,但我无法通过谷歌找到答案('阅读','缓存'和'文件'不是最适合使用的术语...),所以我想我会尝试人的触摸。提前致谢!
也许你的问题是,[getCacheDir](http://developer.android.com/reference/android/content/Context .html#getCacheDir%28%29)返回** File **,而不是** String **? – dstefanox 2011-02-08 13:30:24