开发APP怎样解决缓存文件的处理?如要保存缓存文件在外部私用存储,需要调用getExternalCacheDir()方法。深圳APP开发公司整理创建文件并写入内容的代码如下所示:
String fileName = "cache. txt";
String content = "cache"; if (isExternalStorageWR()){ File file = new File( getExternalCacheDir(). getAbsolutePath(), fileName); Log. v(" file", "file=" + file. getAbsolutePath()); try { FileOutputStream fos = new FileOutputStream( file); fos. write( content. getBytes()); fos. close(); } catch (Exception e) { Toast. makeText( MainActivity. this, "创建 文件 失败", Toast. LENGTH_ LONG); } }