Android 错误 - 打开失败 ENOENT

标签 android eclipse fileoutputstream

我正在尝试使用一个整数数组来保存一些 block 覆盖率,该数组只是保存一个 block 被执行的次数。但是,由于某种原因,当我尝试写入我创建的一些文件(例如“BlockForHelper.txt”,我专门在 Eclipse 中创建并放置在项目目录中)时,我收到了这个错误:

java.io.FileNotFoundException:  /nfs/guille/groce/users/nicholsk/workspace3/SQLTest/BlockForTest: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:416)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
at com.example.sql2.SQLTest.blockCoverage(SQLTest.java:149)
at com.example.sql2.test.SQLTestCase.testSuite(SQLTestCase.java:41)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:400)
... 18 more

并给我错误:

public void blockCoverage() throws IOException
{
    String coverage = "";
    for (int x = 0; x < 20; x++)
        coverage += x + " " + bb_count[x] + "\n";

    File file = new File("/nfs/guille/groce/users/nicholsk/workspace3/SQLTest/BlockForTest.txt");
    Writer out = new OutputStreamWriter(new FileOutputStream(file)); // Here
    try
    {
        out.write(coverage);
    } finally {
        out.close();
    }
}

有人知道这可能是什么原因吗?

最佳答案

使用 sdk,您无法写入内部存储的根目录。这会导致您的错误。

编辑:

根据您的代码,将内部存储与 sdk 一起使用:

final File dir = new File(context.getFilesDir() + "/nfs/guille/groce/users/nicholsk/workspace3/SQLTest");
dir.mkdirs(); //create folders where write files
final File file = new File(dir, "BlockForTest.txt");

关于Android 错误 - 打开失败 ENOENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11620641/

相关文章:

java - 如何解决 "java.net.BindException: Address already in use: JVM_Bind"错误?

java - Eclipse Java printf 问题 PrintStream 不适用

java - 使用java将一个文件的输出存储在另一个文件中

java - 使用 zip 文件的名称命名 Zip 文件夹

java - 如何将多个视频文件一起写入以创建一个视频文件

java - 如何在android中持续检查文本更改事件?

android - jQuery Mobile - 绑定(bind) Android "Next" key

java - 用 eclipse 导出可运行的 jar,想要使用图像文件

android - 是否可以获得我的 Android 设备的源代码?

android - Intent.putExtra 列表