Scratch for Java

File::save()

Saves the object to a JSON-File at the given path.

Examples

import org.openpatch.scratch.extensions.fs.*;
 
public class FileSave {
 
  public FileSave() {
    var settings = new Settings();
    settings.name = "Hi";
    settings.value = 10;
    File.saveXML("settings.xml", settings);
    File.save("settings.json", settings);
 
    Settings loadedSettings = File.loadXML("settings.xml", Settings.class);
    System.out.println(loadedSettings.name);
 
    loadedSettings = File.load("settings.json", Settings.class);
    System.out.println(loadedSettings.name);
  }
 
  public static void main(String[] args) {
    new FileSave();
  }
}
 
class Settings {
 
  public String name;
  public int value;
}
 

View on GitHub

Syntax

Java

.save(path, obj)

Scratch

save (path) (obj)

Parameters

Name Data Type Description
path String Path to a JSON-file.
obj Object An Object.

Return

save()