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

  • Home
  • SEARCH
  • 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 7887571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:36:53+00:00 2026-06-03T05:36:53+00:00

I am trying something simple as creating a text file and then send it

  • 0

I am trying something simple as creating a text file and then send it as attachment. While it works fine if I use the sdcard I don’t know where to put it in the “standard data folder” so my app works actually for everyone without sdcard (and the file is somewhat invisible)

While this code works, I put the questions in the <- * comment.

When creating the file:

String FILENAME = "myFile.txt";
    String string = "just something";

    // create a File object for the parent directory
    File myDirectory = new File("/sdcard/myDir/");  // ******** <- what do I have to put HERE for standard data folder????
    // have the object build the directory structure, if needed.
    myDirectory.mkdirs();
    // create a File object for the output file
    File outputFile = new File(myDirectory, FILENAME);
    // now attach the OutputStream to the file object, instead of a String representation
    FileOutputStream fos = null;
   //always have to put try/catch around the code - why? I don't know
    try {
        fos = new FileOutputStream(outputFile);
    } catch (FileNotFoundException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

     //again have to put try/catch around it - otherwise compiler complains
    try {
        fos.write(string.getBytes());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }

When sending the file:

public void doSendFile() {
    String fileName = "/sdcard/myDir/myFile.txt"; // ******** <- what do I have to put HERE for standard data folder????
    Intent i = new Intent(Intent.ACTION_SEND);
    try {
        mainDataManager.logFileHandle.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { "to@someone.com" });
    i.putExtra(Intent.EXTRA_SUBJECT, "subject");
    i.putExtra(Intent.EXTRA_TEXT, "text");
    Log.i(getClass().getSimpleName(),
        "logFile=" + Uri.parse("file://" + fileName));
    i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + fileName));

    try {
        startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getBaseContext(),
            "There are no email clients installed.", Toast.LENGTH_SHORT)
            .show();
    }

    }

I found that the file seems to be stored at “data/data/com.xxx.xxxx/databases/myFile.txt on creation.
But when I used this in the attachment, nothing was sent.

So basically all I need is to know how to store a file in local memory and then send it from there. Since not everyone might have an external memory sd card – I assume.

Thanks!

  • 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-03T05:36:55+00:00Added an answer on June 3, 2026 at 5:36 am

    This is becuase the SD card is not protected, so you can write to there in the standart java way as you did.

    In order to write to the Android file system you cannot use this, since every file is protected using an App key to avoid other apps to use it.

    You shoud use openFileOutput() see this tutorial for more info:

    http://www.anddev.org/working_with_files-t115.html

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

Sidebar

Related Questions

Trying something simple and overlooking the obvious I'm sure. Shouldn't Factory_Girl be automatically creating
I am trying something very simple, but for some reason it does not work.
actually I thought I was trying something really simple. ControllerClassNameHandlerMapping sounded great to produce
I feel like I'm trying to do something simple but I am not getting
Hey guys, I've been trying to build something simple in Flash 8, and I
I'm trying to do something very simple, yet I can't seem to find the
I'm trying to do something seemingly simple: ensure that Application_BeginRequest is called for every
I am trying to accomplish something very simple, and I'm hoping someone can point
I'm trying to do something really simple, but starting to realize that dates in
I'm trying to do something fairly simple, but for the reason of me probably

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.