In my app I import date from a csv file to a list using the file component. The csv file is stored in the app and I use //book1.csv to access it. This works fine in the companion but not in the packaged app. Just want to know how I should modify the path before packaging the app? (the file is stored in the assets folder with the apk)
--
Reads text from a file in storage. Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt. To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes). If a filename does not start with a slash, it will be read from the applications private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.
Saves text to a file. If the filename begins with a slash (/) the file is written to the sdcard. For example writing to /myFile.txt will write the file to /sdcard/myFile.txt. If the filename does not start with a slash, it will be written in the programs private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging. Note that this block will overwrite a file if it already exists. If you want to add content to a file use the append block.
--
Actually I did go through these instructions but it was not working for me.
--
ReadFrom(text fileName)
SaveFile(text text, text fileName)
--
Actually I did go through these instructions but it was not working for me.
"If a filename does not start with a slash, it will be read from the applications private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion."
I understand this to mean that I should just write the name of the excel file without any slashes (eg.book1.csv) in the read block. But this doesn't work for me. What am I doing wrong?
--
Without blocks, everyone here just guesses azar. What you say you do may not actually be what you are doing. Is that possible? A screen image helps and possibly you might mention what the structure of the csv fill looks like and how large a file you are working with. What happens exactly when you request the read of the csv on your device? Do you get an error message? Can you locate the csv file on your device using an outside app (many devices come with a File app... you type book.csv and it will try to find the file on your Android). Use it to find the csv and its total path on your device and if the file is not located in the assets, point to where it is on the sdCard perhaps.
You can try book1.csv //book1.csv /book1.csv and perhaps the app will find the file.
Also, AI2 cannot read Excel files, it can read a text csv file.
--
you said, you uploaded to csv file into the assets of your app, are you sure?
in this case, you have to use 2 slashes to read from it like this//book1.csv
To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes)
To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes)
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.
--
Actually I did not include a screenshot as there wasn't a whole lot of code. I was just using the read from block (screen attached).
you also might want to provide a screenshot of the media section of the designer
--
After the file is read I convert it to a list using the list from csv component. All of this works fine in the companion.
However, when I package the app I get the book1.csv not found error. I have tried both "//book1.csv" and "book1.csv" in the read from block. The csv file is uploaded with the app the same way that images or other media files are uploaded.
--
that looks fine, but without having that block in a button click event or similar this will not help...
where exactly do you call that block?
also a screenshot of the File.GotText event could help us to help you
--
I am attaching the screenshots of the file.gottext and media sections. The read from file block is under a button click event.
However, I am very sure that there is no problem with the code. Everything works perfectly when I run the app in the companion. The csv file is read, converted to a list and the results displayed on the screen. The file not found error only comes up when I press the concerned button in the packaged app.
I think I am supposed to change the file path before building the apk. I have tried entering the file name with double slashes, single slash, three slashes and without slashes. None work in the packaged app. I even tried //assets/book1.csv.
--
file names are case sensitive
in your case, you have to use //Book1.csv
note the capital B
--
That worked. Would never have thought of that.
--
댓글 없음:
댓글 쓰기