2

I'm trying to read a file, and I keep getting an error saying ENOENT(no such file or directory).

I made the .txt file on my computer, and then I wanted to use that. I've tried putting the file in many different places, the assets folder, in data/data/files and I keep getting the error. Can someone help me?

This is the code I have written.

    try {
        FileInputStream fis = openFileInput("permissions.txt");
        DataInputStream dataIO = new DataInputStream(fis);
        String strLine = null;
        int i =0;
        while((strLine = dataIO.readUTF()) != null){
            i++;
            String[] temp = strLine.split(":");
            if(temp[0].contains("String")){
                PermissionNames.names[i] = remove(temp[0]);
            }
            PermissionNames.descriptions[i] = temp[1];

        }
        dataIO.close();
        fis.close();

    }catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
nickn
  • 184
  • 1
  • 13

2 Answers2

0

Do you want to read from the SDCard or from resources within the project?

If you are trying to save this file on the SDCard then look at this link.

Else if you are trying to read a file not in the SDCard then you will want to look at this link.

Community
  • 1
  • 1
Miguel
  • 1,157
  • 1
  • 15
  • 28
0

yes it should give you exception, because you are trying to access a file that doesn't exists, if you have the file in your assets folder, then at first run copy it to your application path getFilesDir() then you can read it in the way you are doing.

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77