• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Save to a file

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I'm trying to save a user entered name in password to a file. Not sure why Im having so much trouble with this but I cant get it working.

It stops working correctly right as I start using FileOutputStream. I imagine I'm doing something simple that I'm just missing.

Any Help would be appreciated!!!

 
Ranch Foreman
Posts: 126
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my experience with Android development, it's usually permission issues that mess you up. You request permission for READ_EXTERNAL_STORAGE, but it seems you are trying to write a file. Do you get write permission at some other time?

If you are only writing out text, then you can use the PrintWriter which is a class specifically made to easily write text to disk.

I think you should call flush() before close(). Though closing it may flush it for you, it's not guaranteed for all classes!

Does the Toast.makeText execute? Is the file path what you think it should be?
 
Brian Toulouse
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've adjusted it to WRITE_EXTERNAL_STORAGE, and I have the     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in the xml manifest as well.

I'll check out PrintWriter, Im not familiar with it.

Thanks for the tip, I'll add flush() to be safe.

And It does not make it to the toast statement. RIght where I put the comment   on line 25 is where it stops working.
 
Saloon Keeper
Posts: 6205
157
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my response to the other post where you asked (in the future, please don't post the same question multiple times):

It stops working correctly right as I start using FileOutputStream.


What does that mean? What does or does not happen? If there is a stack trace in the logcat, post it in its entirety.

Note that in addition to READ_EXTERNAL_STORAGE you should also ask for WRITE_EXTERNAL_STORAGE.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!