Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Stack Overflow challenge!

Name: Anonymous 2010-08-21 20:20

1. Create a new text file called "fileio.txt"
2. Write the first line "hello" to the text file.
3. Append the second line "world" to the text file.
4. Read the second line "world" into an input string.
5. Print the input string to the console.

Name: Anonymous 2010-08-22 10:44

var fs   = require("fs");
var sys  = require("sys");
var path = "fileio.txt";

fs.writeFile(path, "hello", function (error) {
    fs.open(path, "a", 0666, function (error, file) {
        fs.write(file, "\nworld", null, "utf-8", function () {
            fs.close(file, function (error) {
                fs.readFile(path, "utf-8", function (error, data) {
                    var lines = data.split("\n");
                    sys.puts(lines[1]);
                });
            });
        });
    });
});

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List