0

I need to access myfile.txt file using FileReader in Android , please suggest me where to add the text file in Eclipse. I tried it adding it in Resource and Asset but I am getting File not found issue.

FileReader fr = new FileReader("myfile.txt");

Even

File ff = new File("myfile.txt");

File Supports only the below listed parameters

enter image description here

FileReader Supports only the below listed parameters

enter image description here

Note: I want solution for this issue , only with FileReader or File

Nakkeeran
  • 15,296
  • 1
  • 21
  • 22

2 Answers2

1

The directory would be /res/raw/ this is where you put all your extra resources. you can refer to it using getResources().openRawResource(resourceName) and check here Android how to get access to raw resources that i put in res folder?

EDIT:

how can i edit the text files in assets folder in android in short the easiest way would be to copy the file to external directory then do your stuff there link is here Android: How to create a directory on the SD Card and copy files from /res/raw to it?

One thing to mention - prior to 2.3 the file size in the assets cannot exceed 1MB.


hope it helps abit

Community
  • 1
  • 1
Sergey Benner
  • 4,421
  • 2
  • 22
  • 29
1

That's how I obtain my file from the SD card, perhaps this can be some use to you.

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
        File options = new File(getAppDirectory(), "portal.xml");
}

The getAppDirectory method used in the bit of code looks like this :

private String getAppDirectory() {
    return new String(Environment.getExternalStorageDirectory().toString() 
            + "/foldername/foldername/");
}

After this bit of code I also make sure the file exists and what not before I attempt to read from it.

Jean-Philippe Roy
  • 4,752
  • 3
  • 27
  • 41