-
Notifications
You must be signed in to change notification settings - Fork 0
JsonFile
Page Index:
JsonFile is the core implementation in SimpleJSON that represents a typical JSON file. Every component in SimpleJSON that interacts with files, such as readers and configurations, uses it to accomplish any desired tasks. JsonFile acts similarly to java.io.File, however with extra compatibility to interact with JSON text.
JsonFile comes with eight different constructors, to allow as much convenience as possible. When initiating a new JsonFile, an I/O call is made to the file. This call:
- checks whether the file exists or not.
- creates the file (if desired in construction) if it does not exist already
- checks if the file is empty or not
- if the file is empty, it would write
{}(which is an empty JSON object) to it, to allow it to be used by any component such as readers and configurations.
Hence, all direct calls to a JsonFile constructor will throw a java.io.IOException. Alternatively, if you are sure initiating a JsonFile will be safe and has zero chance of throwing an error, then you can use JsonFile#of(parameters). Every constructor has a #of() counterpart, giving the developer flexibility in declaring JsonFiles.