The File methods in B4J are identical to B4A File methods.
Text file methods
File.WriteString - Writes the given text to a new file.
File.ReadString - Reads a file and returns it content as a string.
File.WriteList - Writes all values stored in a list to a file. All values are converted to string type if required. Each value will be stored in its own line.
Note that if a value contains the new line character it will saved over more than one line and when you read it, it will be read as multiple items.
File.ReadList - Reads a file and stores each line as an item in a list.
File.WriteMap - Takes a map object which holds pairs of key and value elements and stores it in a text file. The file format is known as Java Properties file: .properties - Wikipedia, the free encyclopedia
The file format is not too important unless the file is supposed to be edited manually. This format makes it easy to edit it manually.
One common usage of File.WriteMap is to save a map of "settings" to a file.
File.ReadMap - Reads a properties file and returns its key/value pairs as a Map object. Note that the order of entries returned might be different than the original order.
If you want to write objects or collections other than simple lists or maps then you can use RandomAccessFile.WriteObject / ReadObject or use KeyValueStore class.
Folders
File.DirAssets - The assets folder holds the files that were added to the Files tab. This is a virtual read-only folder. When you compile your program in Release mode the files are packaged inside the Jar files.
File.DirTemp - A temporary folder.
File.DirApp - The program folder. This is the path to the jar file. Note that on Windows it might be read-only (if the program is installed in Program Files).
File.DirData - A folder suitable for writing files. On non-Windows it is the same as File.DirApp. On Windows it points to the user data folder. For example:
Text file methods
File.WriteString - Writes the given text to a new file.
File.ReadString - Reads a file and returns it content as a string.
File.WriteList - Writes all values stored in a list to a file. All values are converted to string type if required. Each value will be stored in its own line.
Note that if a value contains the new line character it will saved over more than one line and when you read it, it will be read as multiple items.
File.ReadList - Reads a file and stores each line as an item in a list.
File.WriteMap - Takes a map object which holds pairs of key and value elements and stores it in a text file. The file format is known as Java Properties file: .properties - Wikipedia, the free encyclopedia
The file format is not too important unless the file is supposed to be edited manually. This format makes it easy to edit it manually.
One common usage of File.WriteMap is to save a map of "settings" to a file.
File.ReadMap - Reads a properties file and returns its key/value pairs as a Map object. Note that the order of entries returned might be different than the original order.
If you want to write objects or collections other than simple lists or maps then you can use RandomAccessFile.WriteObject / ReadObject or use KeyValueStore class.
Folders
File.DirAssets - The assets folder holds the files that were added to the Files tab. This is a virtual read-only folder. When you compile your program in Release mode the files are packaged inside the Jar files.
File.DirTemp - A temporary folder.
File.DirApp - The program folder. This is the path to the jar file. Note that on Windows it might be read-only (if the program is installed in Program Files).
File.DirData - A folder suitable for writing files. On non-Windows it is the same as File.DirApp. On Windows it points to the user data folder. For example:
B4X:
C:\Users\[user name]\AppData\Roaming\[AppName]
Last edited: