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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:44:04+00:00 2026-06-10T05:44:04+00:00

In order to write to a file on sdcard to add android.permission.WRITE_EXTERNAL_STORAGE in AndroidManifest.xml.

  • 0

In order to write to a file on sdcard to add android.permission.WRITE_EXTERNAL_STORAGE in AndroidManifest.xml. What need to add / do to keep a record of the device memory (flash / application folder)?

Write function:

bool write_to_file(const std::string & file_name, const std::string & text)
{
     bool res = false;

     std::ofstream stream (file_name.c_str (), std::ios::out);
     stream.clear();
     if (! stream.fail()) {
         res = true;
         stream << text.c_str() << std::endl;
     }
     else {
         LOGE ("std :: ofstream: wtire error");
     }
     stream.close();

     return res;
}

Call example

std::string file("/sdcard/text.txt");
write_to_file(file, "simple text"); // OK !!!

std::string file("./text.txt");
write_to_file(file, "simple text"); // ERROR !!!
  • 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-10T05:44:05+00:00Added an answer on June 10, 2026 at 5:44 am

    The trick is passing the right file name to the native code. In Android, you use Context.getDir() to retrieve a data folder location in the phone memory. Like this:

    File Path = Ctxt.getDir("Data");
    File FName = new File(Path, "MyFile.txt");
    

    Then pass FName.toString() into the native library somehow. The pasted snippet won’t be directly callable from Java – the glue code is missing.

    In versions of Android that I know of, the file path above would correspond to the following filesystem path: /data/data/com.mypackage/app_Data/MyFile.txt. But you cannot rely on that.

    Writing to arbitrary paths of the device filesystem is prohibited by OS permissions. You have your sandbox, go play in it. Such is the smartphone way.

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

Sidebar

Related Questions

In my android app I try to create a xml file on sdcard. I
I need to write a module that sends order data to an epayment service,
I have an XML file whose contents I want to sort by document order
I am writing a python script in order to write a tex file. But
In order to write to a new file , I do the following :
Question: In order to write a C# interface to libespeak, I need to convert
I'm using DataOutputStream of Java IO in order to write to a file but
I need some utility class to use in order to write some results to
Assume we have 3 processes, they write to a specific file by order, in
How to use AsyncAppender in log4j in order to write log message 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.