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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:23:45+00:00 2026-06-13T05:23:45+00:00

I am using phonegap file reading functionality, once i read the content and i

  • 0

I am using phonegap file reading functionality, once i read the content and i will do some functionality with that content, once that over i am calling file truncate functionality. In that i can’t truncate any value. Help me to fix this issue.

removeFileContent();

function removeFileContent(){
    console.log("Inside remove file content");
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileTruncate, onProcessFailure);
};

function gotFileTruncate(fileSystem){
    console.log("Inside get file path for remove content");
    /** Function to get file path */
    filePath = getFilePath(device.platform);
    console.log("Device File Path to remove content-->"+this.filePath);
    fileSystem.root.getFile(filePath, null, gotFileEntryTruncate, onProcessFailure);
}

function gotFileEntryTruncate(fileEntry){
    globals.raiseLog("Inside file to truncate call");
    globals.raiseLog("File Name-->"+fileEntry.name);
    fileEntry.createWriter(gotFileWriter, onProcessFailure);
}

function gotFileWriter(writer){
    globals.raiseLog("Inside file writer to truncate file content");
    globals.raiseLog("Content length-->"+writer.length);
    //writer.truncate(10);
    writer.onwriteend = function(evt) {
        writer.truncate(0);
        writer.onwriteend = function(evt) {
        };
    };
    writer.write("");
    globals.raiseLog("Content length after truncate-->"+writer.length);
}

In the above gotFileWriter() if i check for writer.length its still showing some count. I dont know how come we can check the file gets empty. I having some text inside that file. Need to clear the file when i finish the reading of the file. I am calling removeFileContent() after i finish the reading functionality. Kindly help.

  • 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-13T05:23:46+00:00Added an answer on June 13, 2026 at 5:23 am

    The way your code is written you may get a false positive that the file still has contents in it. Move your:

    globals.raiseLog("Content length after truncate-->"+writer.length);
    

    into your onwriteend function as the write call is async and may not finish before your log is printed.

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

Sidebar

Related Questions

I'm looking into using PhoneGap for an iOS app so that I can utilize
I am using Phonegap file upload to upload SVG files to my server. It's
I am using phonegap file api to create a directory and create a file
I am trying to write a file in android using phonegap cordova 1.5.0. Below
I wanted to access my existing .db file from sdcard using phoneGap but method
I'm using PhoneGap. And read it and created my work. http://docs.phonegap.com/en/1.9.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android And i added
I've built some pretty straight forward apps earlier using phonegap for android. Now i'm
Note- even though im using phonegap, the question is not about some issue in
I'm trying to work with files on IOS, using Phonegap[cordova 1.7.0]. I read how
I am developing an application for Android using phonegap. When I include phonegap.js file

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.