• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

read/write file

 
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic