Scratch for Java

File()

Browser availability: desktop-only.

This API requires the desktop runtime. Browser declarations may report the limitation without performing the operation.

Saves objects as JSON files and loads them again: their public fields and bean properties (getters and setters), with lists, maps, arrays, enums and nested objects.

Usage examples:

// Save an object as JSON
File.save("/path/to/file.json", myObject);
 
// Load an object from JSON
MyClass obj = File.load("/path/to/file.json", MyClass.class);

Note: The file paths can be absolute or relative. A relative path is relative to the working directory; a file that is only on the classpath (inside a jar) is read from there.

For save games, SaveData is safer: it keeps the last save when writing fails and stores in the player's own folder.

Syntax

Java

new File()
File()

Create Shareable URL

Select Sections