[android] Android Error - Open Failed ENOENT

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

and gives me the error:

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?

This question is related to android eclipse fileoutputstream

The answer is


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

Edit :

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");

Put the text file in the assets directory. If there isnt an assets dir create one in the root of the project. Then you can use Context.getAssets().open("BlockForTest.txt"); to open a stream to this file.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to fileoutputstream

Android Error - Open Failed ENOENT Java FileOutputStream Create File if not exists How to write data with FileOutputStream without losing old data? file.delete() returns false even though file.exists(), file.canRead(), file.canWrite(), file.canExecute() all return true