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 7987731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:13:59+00:00 2026-06-04T12:13:59+00:00

I have written the following code to write to a file on external storage:

  • 0

I have written the following code to write to a file on external storage:

    public static BufferedWriter out;
    private void createFileOnDevice(Boolean append) throws IOException {
            File Root = Environment.getExternalStorageDirectory();
            Log.d("File",Root.toString());
            Root.setWritable(true);
            Root.setReadable(true);
            Log.d("File","Writable: " + Root.canWrite());
            if(Root.canWrite()){
                 File  LogFile = new File(Root, "/Android/DriverInterfaceSystem");
                 if(!LogFile.mkdirs()){
                     Log.d("File","Couldn't make directories");
                 }
                 LogFile = new File(LogFile, "/trace.txt");

                 Log.d("File",LogFile.toString());
                 try{
                     FileWriter LogWriter = new FileWriter(LogFile, true);
                     LogWriter.write("--- New Record ---");
                     out = new BufferedWriter(LogWriter);
                 } catch(IOException e){
                     Log.d("File","FileWriter failed");
                 }

                 out.write("New record");

            }
    }

I have set permissions in Manifest to WRITE_EXTERNAL_STORAGE.

I know that having both a FileWriter and BufferedWriter is redundant, but I was testing if it was just one of them that wouldn’t work.

When I run, the file is created in the correct location, but the program refuses to write either “– New Record –” or “New Record” to the file, the file is just empty.

Given that the file is created, it seems that I’m missing one really simple step, but I’m damned if I can see it. Any thoughts?

  • 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-06-04T12:14:00+00:00Added an answer on June 4, 2026 at 12:14 pm

    I think you have to call flush() for it to actually write to the file. I think just calling write(…) only adds it to the buffer to be written. Here a quick example of usage:

    FileWriter fWriter;
    try{
        fWriter = new FileWriter(“\sdcard\filename.txt”);
        fWriter.write(yourString);
        fWriter.flush();
        fWriter.close();
    }catch(Exception e){
        e.printStackTrace();
    }
    

    Hope this helps.

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

Sidebar

Related Questions

I have written the following code to write a file on my local file
I have written a following code to get just the file name without extension
i have written the following code to download file. java.io.BufferedInputStream in = new java.io.BufferedInputStream(new
I have written the following scala code to download a file . The file
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in
I have written the following code choice /m Do you want to add another
I have written the following code. But it is removing only &nbsp; not <br>
i have written the following code: As you can see there is a for
I have written the following code in Perl. I want to iterate through a

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.