My original problem and question was about reading data from outside of AppInventor/data/ directory. Thanks to Anke I now have a better understanding of the filesystem but I still could not read from outside locations. The error is about file not existing so I think something is wrong with my path (I tried all sorts of variations, including path shown by file manager in details.
To proceed, I modified the application (not AI2) that generates the file so that it puts the file into AppInventor/data/ folder. So my question still remains but I have a workaround.
Next, I read the file and it worked fine. Now the thing is that the other app keeps writing (appending data) to the file. In my AI2 app, I would like to read only any newly arrived data. However, ther read operation on file objects has no seek/position parameter. I can only read the entire file, every single time. This is okay for a while but as the file grows, reading the entire contents again and again (just to get any newly appended data) becomes slow.
So, Chris, yes, your suggestion works. One could also keep a copy of the previous read operation and see how the old and the new differ (at the end) if at all. I cannot do this because the file keeps growing the reading it repetitively at high rate becomes prohibitively slow.
This is where I asked about tail. Timai, yes, I wanted to tail'n'follow ("tail -f") the file, or find some way to seek to a position before the read operation. Since this is a different question, I spinned up a new thread. It got closed but in it, Peter suggested a "Linux command" extension. And it almost works. I can execute Linux commands and get back stdout, I have tail on my system. Unfortunately, I then get back to the original problem. I am not sure what the working directory of the run
method is. It is not AppInventor/data/ I tthink. And, unfortunately, I still do not know how to point to a file in AppInventor/data/ or in a directory of another application.
I will now end by pasting from the other thread to show what I can and cannot do when running Linux commands. Particularly, ls
shows only some directories/files (perhaps due to their ownership). If only I can point tail at the correct [path-to]/AppInventor/data.
Pasted:
I can run "echo aha" --> "aha"
"uname" --> "Linux"
"ps" --> "... info about one process ..."
"tail --version" --> "toybox 0.8.0-android"
"tail --help" --> "... -n ... -c ... -f ..."
"ls" --> "" // EMPTY
"ls /" --> "" // EMPTY
"ls /system/" --> "... whole bunch of directories including bin ..."
"ls /system/bin/" --> "" // EMPTY
(I figure I am getting no output (EMPTY) in some cases due to permissions/file ownership.)
I would really like to run "tail -f ..." but there are no events to get the output as it is appended to the file. No worries, I think I can use "tail -n ..." to get the last few lines, compare the result to previous result and see what changed. If I can do this fast enought, it should work, So this is my current working plan... but I am running into trouble specifying the correct file path. My file is located in AppInventor/Data, let's call in tailme.txt
I need to run " tail -n 4 [some path]/tailme.txt " but I can't figure out the path to AppInventor/data location. Any idea?