android - 创建文件android时出错

标签 android file filenotfoundexception

当我在 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

目录存在。异常(exception)是“FileNotFoundException”

最佳答案

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

关于android - 创建文件android时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24913485/

相关文章:

java - 使用 Java 读取结构化二进制文件的最佳方法

java - Eclipse,无法读取Java类中的文本文件

android - 如何在 Android 中点击 5 分钟后禁用按钮

Android - popUpWindow 中的 DatePicker

python-3.x - Python 写入文件时出现 unicode 错误

php - 如何使用 PHP 安全地将 JSON 数据写入文件

java - Android 文件选择器中的 FileNotFoundException

android - 更新失败 java.io.FileNotFoundException

java - 为 android 中的所有 Activity 注册监听器的全局类

c# - 在 xamarin-forms 中的 xaml 内容页面中嵌入和数据绑定(bind) android 微调器