IOException on File.ReadList

GHosaPhat

Member
I'm having some difficulty with reading a text file into a List object for my app. I've verified that the file exists, but as soon as I call the ReadList method, I get a java.io.IOException. I've tried several different ways to get there, but I keep coming up with the same results. Here's the basic B4A code I've got (taken from the tutorial):
B4X:
Dim NerdWords As List

NerdWords = File.ReadList(File.DirAssets, "nerd.txt")
Msgbox("Items in NerdWords = " & NerdWords.Size & CRLF & "Item #3 is: " & NerdWords.Get(2), "")
I tried initializing the NerdWords object before calling the ReadList method, but no change.

I was afraid that it might be a permissions issue with trying to get the info from the DirAssets location, so I tried to copy the file to the DirInternal folder with the following:
B4X:
If File.Exists(File.DirInternal, "nerd.txt") = False Then
   File.Copy(File.DirAssets,"nerd.txt",File.DirInternal,"nerd.txt")
End If
With that code, I get the IOException on the File.Copy line. I've also tried all of this with a Map object, but I'm getting similar results. It seems like there's some issue getting the information from the DirAssets folder.

I even tried using a TextReader/Writer to "manually" copy the file line-by-line from the one in the Dir.Assets to a new file in DirInternal, but as soon as I tried to do anything with the file in DirAssets, it gives me the IOException. I'm still using the trial version as I get a feel for things, so I don't know if that has anything to do with it, but I'm kinda stuck right now until I figure this piece out. Any assistance would be greatly appreciated.

:sign0104:

EDIT: One thing I just thought of: Is there a size limit for the List object? The file is 1.4MB in size, and has about 168.5K lines of text.
 
Last edited:

margret

Well-Known Member
Licensed User
Longtime User
What is the format in the "nerd.txt" file? Can you post just a small piece of the text file, say 10 lines, etc. Can you access this file fine on the development machine? Is the name on the development machine, in the files folder, also nerd.txt in small case? I don't know of any limit in the trial version that should cause this issue.
 
Upvote 0

GHosaPhat

Member
Is the name on the development machine, in the files folder, also nerd.txt in small case?
Yes, the file name in the directory structure is in lower case.

Can you access this file fine on the development machine?
Yes, I can open and modify the text file manually in my text editor.

What is the format in the "nerd.txt" file? Can you post just a small piece of the text file, say 10 lines, etc.
The file is just a list of words that can be used in my app. Example data:

among
analog
behavior
catalog
center
color
colors
defense
favor
favorite
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Are you testing the code on a real device. If so, what device and what version of Android? Also, copy the file to save the original file and then open the file and delete all but around 100 or so entries. Save the file and try the same code again with this new smaller file just to test and see if it works.
 
Last edited:
Upvote 0

GHosaPhat

Member
Are you testing the code on a real device. If so, what device and what version of Android?
No, I still haven't gotten to the point of migrating to an actual device. Not sure how to do that yet, but I'll worry about crossing that bridge when I get to it.

Also, copy the file to save the original file and then open the file and delete all but around 100 or so entries. Save the file and try the same code again with this new smaller file just to test and see if it works.
So, I cut it down to 100 entries, and it worked. I tried again with the full-sized file, and it errored out again.

I'm using a Galaxy Tab AVD (API Level 8 was the only one I found for that specific device), so I went to check the settings for my AVD. I'm not entirely certain exactly how best to configure an AVD, so I currently have it set for a 16GB SD card and the snapshot is enabled. I don't really know how to read most of the options/settings in there since this is my first attempt to build an Android app, and I don't know if there's anything in there that could have an effect.
 
Upvote 0

GHosaPhat

Member
Thank you all for your assistance. For now I may work with a limited set until I can get it over to the actual device for "final" testing, but that at least gives me a better idea of what to look at. I'll look into the workaround as well, but even with a limited list I should be able to basically finish up most of what I'm trying to do.
 
Upvote 0

GHosaPhat

Member
UPDATE: Well, based on the information from this article, I renamed the full asset file to .arm and the List object was populated properly. Unfortunately, I now run into an Out of Memory error when actually trying to get items from the list through the emulator.

Perhaps when it's running on the actual device, it'll be able to handle things better over there. Even so, I'm a bit concerned by that because my app is going to have to be making repeated calls to this list. I guess we'll just have to see. Thanks again.
 
Upvote 0

joseluis

Active Member
Licensed User
Longtime User
Do you mean .amr?

Maybe this post sheds any light about the memory problem.

I think you might be able to test how much memory it consumes using the AvailableMemory method of the Os library.
 
Upvote 0

GHosaPhat

Member
Yeah, I meant .amr - typos are awesome, especially while writing programming code, aren't they? :p

For now, since I'm still on the trial version, I can't use additional libraries, but I'm trying to work through it a little bit more. I was able to reduce the file size a little bit by removing some of the words I realized I didn't need from the total list, but it hasn't made that much difference yet.

I'm trying to find ways to reduce the amount of memory used, but I'm not sure how I'm going to do that just yet.
 
Upvote 0
Top