Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read/write file

 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning,
Is there any way to read/write a file from a class without extending the Activity? I am tryint to read a file from a Fragment and i cant make it work...

thanks in advance.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to read/write a file from any class. In one of my apps I and reading/writing a file from an ArrayAdaptor.

Perhaps you need to show some code, them we might be able to help you better.
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,
Below is my class code,


how can i create a class and use this piece of code. If i put the code in the fragment class, MODE_WORLD_READABLE cannot be resolved to a variable error is displayed. Only when i add this code to an activity it works.
In general i get a byte[] array and write it to a file. When this was on the activity class it worked great. When i added it to a fragment class it displays the error above.

thanks in advance for the help.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MODE_WORLD_READABLE is defined in Context, and Activity is a subclass of Context. But since you move the code out of the Activity, you need to tell the compiler (and Eclipse) where MODE_WORLD_READABLE comes from, so use Context.MODE_WORLD_READABLE instead.

http://developer.android.com/reference/android/content/Context.html#MODE_WORLD_READABLE
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic