File System Overview
Series 4 JNIOR’s have a file directory that can be interacted with via a command line connection or from the Web UI. Being able to interact with the file directory and read/write files to it can be a useful tool when creating applications, from recording versioning numbers to writing data to reference later. Below is a small example below that writes and then reads to a file.
Directories and File Interaction
To start a file object is declared with the directory of the temp folder and the name of the file we are creating which is “test.log”. We also create another file object called directory and we are going to use this to display all the files located under the flash directory in the JNIOR by. We get the files in the flash directory by assigning the value ‘/flash’ to it, and then using the .list() function we can return a string array of all the files under that directory. We declare a local string array called files and populate it with the file names we just got. Then we go through and print out the name of each one. After this we declare a BufferedWriter to create a FileWriter. The FileWriter is then used to write a string to the test.log file we just declared. Next a BufferedReader is declared to create a FileReader. The FileReader is used to the read whatever data is on the file as a string, and since we just wrote to it, it will print out what we’ve writer to the file.
View on GitHub
Filing Example
I put the built jar file of this example application into the JNIOR’s flash folder and ran it from the Web UI’s console tab. As you can see it, application runs and prints out the text that was written to the file. You can also see the test.log file is created in the temp folder.