Android Question [SOLVED] File.readlist, first item is empty

Discussion in 'Android Questions' started by alwaysbusy, Feb 27, 2015.

  1. alwaysbusy

    alwaysbusy Expert Licensed User

    Hi,

    I'm trying to read a file using the file.readlist() method. For some reason the first item in the list is empty, although there is no CR of LF at the beginning.

    Attached is the file in question, and here is the hex view of the first bytes:

    [​IMG]

    Any ideas why?
     

    Attached Files:

  2. DonManfred

    DonManfred Expert Licensed User

    how did you write the file and what are you writing there?
    Some code would be helpful.
     
  3. alwaysbusy

    alwaysbusy Expert Licensed User

    The files are created in another language (Xojo on PC). They contain the description of a SQLite database that B4A reads and then uses to create the db.

    Only three lines in it:

    First line:
    <Database>FYTO_Alain.sq3</Database> <-CR

    second line:
    <Table>FYTO_REGISTRATIE;4,FYTO_REGISTRATIE_SYSID,FYTO_REGISTRATIE_SYSID,0;4, .......</Table> <-CR

    Third line:
    <Screens>4:27;5:12;6:5;7:26;8:5;9:5;10:11;11:11;16:6;17:6;13:25;12:25;19:19;18:25</Screens> <-CRLF

    Code:

    Dim txtIN As List
    txtIN.Initialize
    txtIN = File.ReadList(mGlobal.BuildPath, "CurrentDB.Schema")

    Result in txtIN after this code:

    txtIN.Get(0)<- the weird empty string
    txtIN.Get(1) <Database>FYTO_Alain.sq3</Database>
    txtIN.Get(2) <Table>FYTO_REGISTRATIE;4,FYTO_REGISTRATIE_SYSID,FYTO_REGISTRATIE_SYSID,0;4, .......</Table>
    txtIN.Get(3) <Screens>4:27;5:12;6:5;7:26;8:5;9:5;10:11;11:11;16:6;17:6;13:25;12:25;19:19;18:25</Screens>
    txtIN.Get(4)<- an ampty string, but this one makes sence as there is an CRLF at the end, ergo ReadList makes two lines
     
  4. Troberg

    Troberg Well-Known Member Licensed User

    My first instinct in cases like these is to check character encoding. Is it one encoding and ReadList expects another?

    Otherwise, simplify. Make a simple file (in a texteditor) with, say, A, B, C and D in it, just to make sure there isn't anything you don't see in the data. If this doesn't work, it's probably Erel's problem, if it works, well, then you can gradually do more complex test cases until you find the problem.
     
  5. alwaysbusy

    alwaysbusy Expert Licensed User

    Ok , found it. Just for further reference if someone else encouters this.

    The problem is the mix of the two type of EOLs I used. If I use all CR chars OR all CRLFs, readlist works as expected.

    But because in my case I used CR for every line, and CRLF at the end, ReadList() somehow got confused.
     
    ZJP and thedesolatesoul like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice