【问题标题】:error creating file android错误创建文件android
【发布时间】:2014-07-23 14:37:51
【问题描述】:

当我在 Nexus 5 上运行应用程序时,文件没有问题,但在另一部智能手机中我遇到了问题,我认为可能是空格,我将其删除。

代码是:

    File file = new File(directory,new SimpleDateFormat("dd-MM-yyyy-HH:mm:ss",Locale.ROOT).format(new Date()).toString()+"-"+idUser+"-"+idTest+".txt");
    FileOutputStream outputStream = new FileOutputStream(file);

路径文件:/storage/sdcard0/Nexio/Tests/23-07-2014-16:33:11-alex-0.txt

目录存在。例外是“FileNotFoundException”

【问题讨论】:

  • 您的目录在哪里?你看过这个吗 - stackoverflow.com/a/7658403/713778
  • 如果您尝试将文件保存在内部存储中(您的应用专用) - developer.android.com/guide/topics/data/…
  • 我认为问题与名称有关,因为如果文件名是“test.txt”,则没有问题。
  • 虽然这可能不是当前的问题(取决于底层文件系统),但在文件名中放置“:”字符是个坏主意。

标签: android file filenotfoundexception


【解决方案1】:

您可能正在使用静态字符串设置目录..这将是我的猜测.. 使用 http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

【讨论】:

  • 问题是因为我在名称文件中使用了字符“:”。我不明白为什么,但是好的,谢谢大家!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-07
  • 1970-01-01
  • 1970-01-01
  • 2017-07-22
  • 1970-01-01
  • 2014-12-23
  • 1970-01-01
相关资源
最近更新 更多