Problem with WriteList and ReadList

klaus

Expert
Licensed User
Longtime User
Hi Erel,

In the attached test ptogram I save a List of typed variable data with WriteList and read it back with ReadList.
The returned List size is 4 times the original size.
There are extra commas in the list read back, why?
(ArrayList) [[Altitude=460.0, Time=0, DistTot=0.0, [COLOR=Red],[/COLOR] Distance=0.0, Longitude=7.145578, Latitude=46.153322, , IsInitialized=true, Speed=14.0, Bearing=0.0, ], [Altitude=459.0, Time=10, DistTot=0.0, [COLOR=Red],[/COLOR] Distance=0.0, Longitude=7.156977, Latitude=46.140693, , IsInitialized=true, Speed=13.0, Bearing=20.0, ], ...
Best regards.
 

Attachments

  • SaveListType.zip
    5.7 KB · Views: 304

Erel

B4X founder
Staff member
Licensed User
Longtime User
File.WriteList writes a line for each item, as vb1992 wrote, some of the items span over more than a single line. When you use File.ReadList it takes each line and treats it as a string item.

These methods should not be used with custom types. You should instead use RandomAccessFile.WriteObject / ReadObject. These methods create a binary file that keeps the original structure.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Or replace the line delimiter character with something like %n%, something that doesnt occur in your regular data
 
Top