Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Android
Save to a file
Brian Toulouse
Greenhorn
Posts: 3
posted 4 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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!!!
public class MainActivity extends AppCompatActivity { EditText uname, pwd; Button saveBtn; FileOutputStream fstream; // SAVE EDIT TEXT FEILDS TO VARIABLES uname = (EditText)findViewById(R.id.editText2); pwd = (EditText)findViewById(R.id.editText4); saveBtn = (Button)findViewById(R.id.button); // onClick listener saveBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String username = uname.getText().toString()+"\n"; String password = pwd.getText().toString(); try { ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE},23); File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File myFile = new File(folder,"user_details"); // This is where the program stops working as intended********************* fstream = new FileOutputStream(myFile); fstream.write(username.getBytes()); fstream.write(password.getBytes()); fstream.close(); Toast.makeText(getApplicationContext(), "Details Saved in "+myFile.getAbsolutePath(),Toast.LENGTH_SHORT).show(); startActivity(new Intent(MainActivity.this,CreatePorfolio.class)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }); } }
Tim Moores
Saloon Keeper
Posts: 7585
176
posted 4 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It stops working correctly right as I start using FileOutputStream.
What does that mean? What does or does not happen?
Note that in addition to READ_EXTERNAL_STORAGE you should also ask for WRITE_EXTERNAL_STORAGE.
Tim Moores
Saloon Keeper
Posts: 7585
176
posted 4 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Dup of
https://coderanch.com/t/728417/mobile/Save-file
. Closing.
This tiny ad is wafer thin:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Saving to external storage public directory
Sum of Arraylist
2 screens, one activity
Passing Arraylist values into Edit Text Fields
getText() help
More...