Android的错误 - 打开失败ENOENT错误、Android、ENOENT

2023-09-12 00:17:36 作者:冷月花魂

我想保存使用整数数组,仅仅保存的块被执行的次数一些块覆盖。出于某种原因,不过,当我试着写,我创建的(BlockForHelper.txt为例,这是我在Eclipse中做专,并放置在项目目录)的一些文件,我得到这个错误:

I am trying to save some block coverage using an array of integers that simply saves the number of times a block is executed. For some reason, though, when I try and write to some files that I created ("BlockForHelper.txt" for example, which I made specifically in Eclipse and placed in the project directory), I get this error:

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();
    }
}

任何人都知道可能会导致什么呢?

Anyone know what might be causing this?

推荐答案

通过SDK,你不能写内部存储的根。这会导致你的错误。

With sdk, you can't write to the root of internal storage. This cause your error.

编辑:

,使用内部存储与SDK:

Based on your code, to use internal storage with 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");