Android Question [Solved]Text file added to project becomes binary file on device. Why?

DataMiser

Member
Licensed User
I have a text file that was created on the PC in notepad. It contains 100 lines of plain text.
I added this file using the files tab in the project.
The file gets placed on the device in the files/virtual_assets folder as expected.

When I try to read the file into a list using the textreader.readlist I get 11 items

I copied the file back to the PC and opened it with notepad and it is nothing like the original.

For example the content was a list of sentences n English
After the file is moved to the device it looks like the bit below
[`vÑ|AÐ)º}IÒ7Ù¦met1$yçkò©=¤

Any idea why this happened and/or what I need to do to include a text file that will be usable on the device.

Also I know that b4a uses LF as a terminator but am wondering if having files that have the CRLF in them would be an issue. Would I need to strip the CR from files that were created on the PC under notepad for example.
 

Mahares

Expert
Licensed User
Longtime User
Use Notepad ++ instead of Notepad. You can download it free. Open file in Notepad ++ and save it in Notepad++, then see what it looks like. Otherwise, post file for members to check it out.
 
Upvote 0

DataMiser

Member
Licensed User
It is just a simple text file, plain English.

If I manually copy the file to the folder on the device it works fine but when I include it under the files tab of the project that seems to be doing something to the file. The file that ends up on the device looks like maybe it is being compressed as it is smaller and contains binary data rather than plain text.
 
Upvote 0

DataMiser

Member
Licensed User
Same result using UTF-8, Previous was using ANSI
I also tried renaming the file to DataFile.Dat but get the same result.

I am thinking I am doing something wrong in terms of how I am adding the file.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use TextReader. Use File.ReadList instead. The result will be the same but it is simpler.

Any idea why this happened and/or what I need to do to include a text file that will be usable on the device.
You don't need to do anything special.

The file is internally compressed but it doesn't matter. You should use the standard file methods and it will return the file content.
 
Upvote 0

DataMiser

Member
Licensed User
Changed the code to
B4X:
cList.AddAll(File.ReadList(File.DirDefaultExternal &"/Virtual_assets","datafile.dat"))

Same result

Only seems to work if I manually copy the file from the PC to the device.

btw. I have not yet updated to 6.80 if that makes any difference
 
Upvote 0

DataMiser

Member
Licensed User
btw I am really liking B4A, very glad I gave it a try.
I have even found that some of my VB.Net code works without any changes and other works with minor changes. Of course some is totally incompatible but it is a nice bonus that I can use some of my existing code when converting my Windows Mobile apps written in VB.Net to Android and B4A.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Great!
I have even found that some of my VB.Net code works without any changes and other works with minor changes. Of course some is totally incompatible but it is a nice bonus that I can use some of my existing code when converting my Windows Mobile apps written in VB.Net to Android and B4A.
The next step is to try B4J ;)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
clist.AddAll(File.ReadList(File.DirAssets, "datafile.dat"))
Can he just do this:
B4X:
clist = File.ReadList(File.DirAssets, "datafile.dat")
I have a feeling you are going to tell me they are the same and I would have wasted a post.
 
Upvote 0
Top