Hi Svein.
At present, you would need to have your file end with a newline to read the final line.
I will add a feature request to have it automatically return the last line of the file if it hits an EOF and to return null if called after hitting EOF.
For your existing application, if the file does end with a newline, I would recommend:
function readTextFile(path){
var textFile = ogscript.createFileInput(path);
var line = "";
try
{
while((line = textFile.readLine()) != null)
{
ogscript.debug(line);
}
}
catch (e)
{
//END OF FILE
}
textFile.close();
ogscript.debug("File closed");
}
Another option would be to read the entire file and split it into an array of Strings based on the newline character:
function readTextFile(path)
{
var textFile = ogscript.createFileInput(path);
var allText = textFile.readString(textFile.getSize());
textFile.close();
var allLines = allText.split("\n");
for (var i = 0; i < allLines.length; i++)
{
ogscript.debug(allLines[i]);
}
}
#DashBoard