An archive of as of Saturday January 26, 2019.

File IO Explanation


I'm really confused on the file IO in Squirrel. I want to store a JSON document into a file, and then retrieve it later. Can someone explain how to write and retrieve an entire file as a string (if it's possible)?


Here's an example:


test <- {a=1, b="two"};

print(jsonencode(test) + "\n");

// Open a file on the micro SD
const FILENAME = "sd:/test.json";

// create and/or open for write
f <- file(FILENAME, "w+");



// open the file for read
f = file(FILENAME, "r");

teststr <- f.readstr(f.len());
print(teststr + "\n");

test = jsondecode(teststr);

print(test.a + " " + test.b + "\n");


Note: After writing the file, if you refresh the file list view in the IDE you should see, and be able to edit the new test.json file.

This post may also be helpful:


Thanks so much! I finally somewhat understand it now, all the guide I could find on the internet for io in squerll confused me beyond belief.