iOS Question problem reading text file

cirollo

Active Member
Licensed User
Longtime User
Hi! I have a file (with custom extension, in this example is myfile.1) like this:

1;ROSSI MARIA;BONGHI;BONGHI; ;;I;0000002397;MAFFEI;ISABELLA;NORM;TS;P
1;ROSSI MARIA;BONGHI;BONGHI; ;;I;0000002398;CALLEA;CARMELA;NORM;TS;P
1;ROSSI MARIA;BONGHI;BONGHI; ;;I;0000002888;STEFANACHI;IRENE;NORM;TS;P
1;ROSSI MARIA;BONGHI;BONGHI; ;;I;0000003447;ALTIERI;SERAFINA;NORM;TS;P
1;ROSSI MARIA;BONGHI;BONGHI; ;;I;0000003532;LASORSA;ANNAROSA;NORM;TS;P
1;ROSSI MARIA;BONGHI;BONGHI; ;;I;0000003650;SALIERNO;GRAZIA;NORM;TS;P

I need to import these data into a sqlite table...

I tried all of these:

B4X:
  Dim SU As StringUtils
     Dim TB As List
     TB.Initialize 
     TB = SU.LoadCSV(sdRoot,Nfile,";") '

B4X:
     Dim TB As List
     TB.Initialize 
     TB = File.Readlist(sdRoot, Nfile)

B4X:
     For Each line As String In File.ReadString(sdRoot, Nfile)

none of these works, I get the error....

Application_Start
Application_Active
EXP_20160427.1, Success=true
Error occurred on line: 204 (sync)
Error reading file. Incorrect encoding
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
FiveStars Scuola -[B4IFile ReadString2:::] + 500
FiveStars Scuola -[B4IFile ReadString::] + 86
FiveStars Scuola -[B4IFile ReadList::] + 70
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 292
FiveStars Scuola +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
FiveStars Scuola -[B4IShell runMethod:] + 574
FiveStars Scuola -[B4IShell raiseEventImpl:method:args::] + 1998
FiveStars Scuola -[B4IShellBI raiseEvent:event:params:] + 1442
FiveStars Scuola __50-[B4I raiseEventFromDifferentThread:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1532
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1590
CoreFoundation CFRunLoopRunSpecific + 516
CoreFoundation CFRunLoopRunInMode + 108
GraphicsServices GSEventRunModal + 160
UIKit UIApplicationMain + 144
FiveStars Scuola main + 108
libdyld.dylib <redacted> + 2
)
 

cirollo

Active Member
Licensed User
Longtime User
this is the file I'm trying to import....(is in the zip)
 

Attachments

  • EXP_20160422_CIRO.zip
    264 bytes · Views: 138
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't get any error when I try to read it:
B4X:
Log(File.ReadString(File.DirAssets, "EXP_20160422_CIRO.1"))

My guess that the actual file that you are trying to load uses a different encoding. You should use File.ReadString2 with the correct encoding (next time it is better to upload a file that demonstrates the problem).
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
Hi Erel! I confirm that I still getting error with that file...

tried (follow your suggestion...) this:

B4X:
    For Each line As String In File.ReadString(sdRoot, Nfile)
            Log(File.ReadString(sdRoot, Nfile))
  
        Next

got this on the debug log...(PS I renamed the file, only removing the _ciro part)

Application_Start
Application_Active
EXP_20160502.1, Success=true << THIS MEANS THE FILE IS DOWNLOADED CORRECTLY
Error occurred on line: 206 (sync) << THIS IS THE LINE For Each line As String In File.ReadString(sdRoot, Nfile) NOTICE THAT sdRoot = File.DirDocuments
-[__NSCFString Size]: unrecognized selector sent to instance 0x17dd9e40
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
CoreFoundation <redacted> + 702
CoreFoundation _CF_forwarding_prep_0 + 24
FiveStars Scuola -[b4i_sync _popolatabelle] + 2842
FiveStars Scuola -[b4i_sync _ftp_downloadcompleted::] + 1654
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 292
FiveStars Scuola +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
FiveStars Scuola -[B4IShell runMethod:] + 574
FiveStars Scuola -[B4IShell raiseEventImpl:method:args::] + 2212
FiveStars Scuola -[B4IShellBI raiseEvent:event:params:] + 1442
FiveStars Scuola __50-[B4I raiseEventFromDifferentThread:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1532
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1590
CoreFoundation CFRunLoopRunSpecific + 516
CoreFoundation CFRunLoopRunInMode + 108
GraphicsServices GSEventRunModal + 160
UIKit UIApplicationMain + 144
FiveStars Scuola main + 108
libdyld.dylib <redacted> + 2
)
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
Hi Erel! my app does before the download (ftp) of the file, and then the reading of its content.
I should create a small app with also the download phase, then I'll post here...

or can you give me some hint about the wrong code???
 
Upvote 0
Top