Skip to content
This repository was archived by the owner on Jun 26, 2019. It is now read-only.
frenzylabs edited this page Dec 14, 2010 · 2 revisions

CoreJS offers File I/O using an object for handling one file instance at a time, and offers several global, simplified methods for working with files.

Global Methods:

// Read a file:
var fileContents = readFile("/path/to/file");

// Write a file: (On success returns true, throws an error on failure
writeFile("/path/to/file", "this is the contents i want in the file");

// Remove a file:
removeFile("/path/to/file");

// Test if an item is a file:
if( isFile("/path/to/something")
{
     // Is file, we good
}

File Object usage: File object uses the same rules for opening a file as C, php, and others.

// Create a new File object:
var file = new File();

// Open the file for reading and writing
file.open("/path/to/file", "w+r");

// Write a string to the file.
file.write("This is a test");

// Read the file's contents
var fileContents = file.read();

// Get the file's path
var currentFilePath = file.getFilePath();

// Close the file.
file.close();

Clone this wiki locally