locked
How to add content to an access file by JavaScript

    Question

  • According to the Metro style app sample "File access sample" I'v know how to create a file and how to write content to the file.

    But I can't find how to add content to the end of a file  in samples as well as in library.

    I need to add some contents to the end of a file,just like the usage in c++:

             ofstream file("example.txt", ios::out | ios::app);

    How to do that in metro apps by JavaScript?

    Here is the code what I referenced:

    function writeLogToStream(userContent)
    {
        if (null != logFile)
        {
            if ("" !== userContent)
            {
                logFile.openAsync   (Windows.Storage.FileAccessMode.readWrite).then(function (writeStream)
                {
                    var dataWriter = new Windows.Storage.Streams.DataWriter(writeStream);
                    dataWriter.writeString(userContent);
                    dataWriter.storeAsync().then(function ()
                    {
                        dataWriter.flushAsync().done(function ()
                        {
                            dataWriter.close();
                        });
                    });
                });
            } else
            {
                
            }
        }
    }
    

    Thursday, April 12, 2012 8:18 AM

Answers