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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:19:39+00:00 2026-06-12T16:19:39+00:00

I am writing into a file using android-ndk . So writing in file is

  • 0

I am writing into a file using android-ndk . So writing in file is taking place using native c code.

It contains some kind of readings that i am putting in using ndk.
On click of a button the writing into a file start. And simultaneously i want to read contents of file and use them into another thread for showing up the values as writing operation might continue for 15 sec and user will have to wait for that much time to see the result so i want to show result one by one as soon as i get it into that file.

Is it feasible ,if yes can show me the way how to go about that?

Well i started with it and right nw its how i am doing it ,,

Thread thr1 = new Thread(r1);
Thread thr2 = new Thread(r2);
thr1.start();
thr2.start();



r1 = new Runnable() {
          public void run() {
            File sdcard= Environment.getExternalStorageDirectory();
            nativeFunction(sdcard +"/readings.txt");
            //takingReading=false;
            readingFile = new File(sdcard +"/readings.txt");

            Log.i("length of file", ""+readingFile.length());
          }
        };




r2 = new Runnable() {
          public void run() {
            try {

                  Thread.sleep(3000);
                  File sdcard= Environment.getExternalStorageDirectory();

                readingFile = new File(sdcard +"/readings.txt");

                Log.i("length of file", ""+readingFile.length());


            } catch (InterruptedException iex) {}
          }
        };

nativeFunction opens

file= fopen(location,"w+");

This function keeps on writing things in file for around 2 minutes,
but i need to continuously get the values entered bye native function so i started 2nd thread but when i check file.length() its always 0.

and when nativefunction write is complete then actual file size comes. So how to get around this problem?

  • 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-12T16:19:41+00:00Added an answer on June 12, 2026 at 4:19 pm

    This should be possible using pthreads. So you need to spawn 2 threads, one doing the writing and other doing the reading. If you are doing it from the same file, you may run into race conditions, so be careful.

    More more info on pthreads, kindly google. It’s commonly used by the Linux world.

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

Sidebar

Related Questions

I am writing some code to add file attachments into an application I am
I am using this class for writing into config file. Code is builted and
I have some code that reads from an ini file in Javascript, using activex
I am writing a XML file into a HTML file using JavaScript. Here is
When I am writing a file into GridFS using grid.put(), which has the same
I'm writing a program that passes data from a file into an array, but
I'm writing a sharepoint web part. It writes logs into a file (by using
I'm having a problem writing Norwegian characters into an XML file using C#. I
I am working with Delphi Prism and creating and writing into binary file using
I am writing into a text file and i am using System.getProperty(line.separator); to go

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.