• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading a text file from assets folders

 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a text file in my assetfolder called myfile.txt. I create a new File Object called File f=new File("myfile.txt"), but a File not found exception occurs.

How can i do this.

Kind Regards.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't create File objects like that. You interact with files through the Activity.openFile[In|Out]put methods.

The "Data Storage" page of the developer's guide talks about this.
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. i am not creating a file, just readfing from it. I have the file in my assets fodler, and wish to display its contents in a TextView.

Could you please point me in the right way by givien me some code snippets

Kind Regards
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't talking about creating files, I was talking about creating File objects - which your post mentioned you were doing. Like I said, that's not how things work on Android.

I mistakenly mentioned Activity.openFile[In|Out]put (which is for application files in internal storage); what you want is actually Activity.getAssets().open(...).
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Got it. Works fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic