Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7679495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:53:25+00:00 2026-05-31T17:53:25+00:00

I want to write data to an output file and save it on a

  • 0

I want to write data to an output file and save it on a mobile device or on a computer harddrive. I am able to get my code below to work, but have to create the directory in one step and then create the file in another. Is there a more effective way to code having to create an non-existing directory before writing a file there?

Thanks

StringBuilder Path = new StringBuilder();
    Path.append(Environment.getExternalStorageDirectory().toString());

    String filename = "test.txt";
    String test_text = "Date, Item, Quantity, Description,";
    File file = new File(Path.toString()+"/" +"Test Folder2/");
    file.mkdirs();
    FileOutputStream file_os = null;
    try {
        File file2 = new File(Path.toString()+"/" +"Test Folder2", filename);
        file_os = new FileOutputStream(file2);
        OutputStreamWriter osw = new OutputStreamWriter(file_os);

        try {
            osw.write(test_text);
        } catch (IOException e) {

            e.printStackTrace();
        }   
        try {
            osw.close();
        } catch (IOException e) {

            e.printStackTrace();
        }

    } catch (FileNotFoundException e) {
        Toast.makeText(QuizSettingsActivity.this, Path.toString(),
                Toast.LENGTH_LONG).show();

    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:53:27+00:00Added an answer on May 31, 2026 at 5:53 pm
    String FILENAME = "test";
    String string = "Date, Item, Quantity, Description,";
    
    FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
    fos.write(string.getBytes());
    fos.close();
    

    For more detail on saving file on external storage follow the link mentioned below:.http://developer.android.com/guide/topics/data/data-storage.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write data into the file in binary form. I was trying
i want simultaneously read and write data into file. Can i use StreamReader and
I am using ofstream() to write data into file, i want the program to
I want to write the bulk of data into xml file ,the data coming
I want to write a .xml file using the following code into the App_Data/posts.
I want to write audio data to stdout, preferably using libsndfile. When I output
I want to write JSON data to a text file using jQuery and PHP.
I want to use iText to write data to pdf. Assembles that I've added
I am writing a photo gallery/sharing website and want to (1) write EXIF data
I want to write a small bit of data from my app to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.