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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:23:51+00:00 2026-05-24T12:23:51+00:00

I tried writing/reading a file in phonegap+android , here is the set up: $(document).ready(function()

  • 0

I tried writing/reading a file in phonegap+android, here is the set up:

$(document).ready(function() {
    document.addEventListener("deviceready", deviceready, true);

    $(document).bind("deviceready", function(){
    //writeFile();
    //readFile();
    });
});

function deviceready() {
    writeFile();
    readFile();
}

// This is just to do this.
function readFile() {
    var d = navigator.file.read('/sdcard/foo.xml', success(), fail());
    console.warn(d);
}

function writeFile() {
    navigator.file.write('/sdcard/foo.xml', "This is a test of writing to a file",
            success(), fail());
}

But on the emulator for Android 2.2, I got the following error message:

08-06 14:21:29.428: INFO/Web Console(936): Error in success callback: Network Status1 = TypeError: Result of expression 'navigator.file' [undefined] is not an object. at file:///android_asset/www/phonegap.0.9.6.js:649

What could be missing and what could be tried?

  • 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-05-24T12:23:52+00:00Added an answer on May 24, 2026 at 12:23 pm

    The following works for me on Android with phonegap-1.0.0:

    <script type="text/javascript" charset="utf-8" src="css-js/phonegap-1.0.0.js"></script>
        <script type="text/javascript" charset="utf-8">
    
        // Wait for PhoneGap to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);
    
        // PhoneGap is ready
        //
        function onDeviceReady() {
            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    
        }
    
        function gotFS(fileSystem) {
            var path = "readme.txt";
            fileSystem.root.getFile(path, {create: true, exclusive: false}, gotFileEntry, fail);
    
        }
    
        function gotFileEntry(fileEntry) {
    
            fileEntry.createWriter(gotFileWriter, fail);
        }
    
        function gotFileWriter(writer) {
            writer.onwrite = function(evt) {
                console.log("write success");
            };
            writer.write("some sample text");
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn Lisp (elisp, actually), and I tried writing the following function
I need to open a file for reading and writing. If the file is
I tried the following code to accomplish the task of reading and writing tiff
I'm reading a file from a SQL server and writing it to disk temporarily
In my application, I am reading a .xml file and writing the data in
I tried writing a program in Java using regex to match a pattern and
I have tried the following program for writing the contents into Spreadsheet. I downloaded
I have a business user who tried his hand at writing his own SQL
I'm writing an app for WM that handles incoming SMS events. I tried making
I was writing some codes in linux using c. When tried to compiled, I

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.