【问题标题】:Android saving file to cache directoryAndroid将文件保存到缓存目录
【发布时间】:2012-09-10 08:40:57
【问题描述】:

我正在尝试做一些简单的事情,比如将文件保存到 Android 中的缓存目录,但我遇到了很多问题。我正在使用简单序列化程序将我的文件写入 xml。

这是我的代码:

public void testWrite(ListDefinitions ld)
{
    Serializer serializer = new Persister();

    String fileName = "sampleExport.xml";
    try {
        File file = new File(mContext.getCacheDir(), fileName);
        file.createNewFile();
        serializer.write(ld, file);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

我不断收到以下错误:

09-18 00:35:06.229: W/System.err(4442): java.io.FileNotFoundException: /data/data/com.main/cache/sampleExport.xml: open failed: EISDIR (Is a directory)

感谢您的帮助。

【问题讨论】:

  • sampleExport.xml 是一个目录,而不是您想要的文件。
  • 感谢您的回复。我将如何将其制作为文件?我基本上想写一个临时文件来缓存目录。

标签: android xml-serialization android-xml java-io android-file


【解决方案1】:

可能您之前创建了目录时调用错误。尝试在设置中清理应用数据。

【讨论】:

  • 其实就是这样!谢谢!
猜你喜欢
  • 2015-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-21
  • 1970-01-01
  • 2022-01-16
  • 2011-07-19
相关资源
最近更新 更多