Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #1 Hello All, I am reading several text files into lists, processing the info and writing them again. One of the files, however has some special characters, tar i connot read correctly. Any ideias ? File: Code: :· 72033258 7203325704/04/2018 :· 72033259 7203325704/04/2018 :µ 72035960 7203596104/04/2018 when I read the file, I get different chars in the lines and when I write the file I also get those char, instead of the origial ones. I have tried using lists and a TextReader, same results.
Hello All, I am reading several text files into lists, processing the info and writing them again. One of the files, however has some special characters, tar i connot read correctly. Any ideias ? File: Code: :· 72033258 7203325704/04/2018 :· 72033259 7203325704/04/2018 :µ 72035960 7203596104/04/2018 when I read the file, I get different chars in the lines and when I write the file I also get those char, instead of the origial ones. I have tried using lists and a TextReader, same results.
KMatle Expert Licensed User Longtime User Apr 6, 2018 #2 Hard without seeing your code. I always use RandomAccessFile. You can write and read any object you like (lists, maps, texts, etc.). Here it is encrypted, too. Code: Dim raf As RandomAccessFile raf.Initialize(MyPath, "config.dat", False) raf.WriteEncryptedObject(MyList, "MySecretPW", raf.CurrentPosition) raf.WriteEncryptedObject(MyMap, "MySecretPW", raf.CurrentPosition) raf.Close Upvote 0
Hard without seeing your code. I always use RandomAccessFile. You can write and read any object you like (lists, maps, texts, etc.). Here it is encrypted, too. Code: Dim raf As RandomAccessFile raf.Initialize(MyPath, "config.dat", False) raf.WriteEncryptedObject(MyList, "MySecretPW", raf.CurrentPosition) raf.WriteEncryptedObject(MyMap, "MySecretPW", raf.CurrentPosition) raf.Close
Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #3 KMatle said: Hard without seeing your code. I always use RandomAccessFile. You can write and read any object you like (lists, maps, texts, etc.). Here it is encrypted, too. Code: Dim raf As RandomAccessFile raf.Initialize(MyPath, "config.dat", False) raf.WriteEncryptedObject(MyList, "MySecretPW", raf.CurrentPosition) raf.WriteEncryptedObject(MyMap, "MySecretPW", raf.CurrentPosition) raf.Close Click to expand... My code is a simple file.readlist. however I am going to try your approach. thanks Upvote 0
KMatle said: Hard without seeing your code. I always use RandomAccessFile. You can write and read any object you like (lists, maps, texts, etc.). Here it is encrypted, too. Code: Dim raf As RandomAccessFile raf.Initialize(MyPath, "config.dat", False) raf.WriteEncryptedObject(MyList, "MySecretPW", raf.CurrentPosition) raf.WriteEncryptedObject(MyMap, "MySecretPW", raf.CurrentPosition) raf.Close Click to expand... My code is a simple file.readlist. however I am going to try your approach. thanks
KMatle Expert Licensed User Longtime User Apr 6, 2018 #4 Pedro Caldeira said: My code is a simple file.readlist Click to expand... With it you can only write/read simple strings. Maybe this is the cause if e.g. a map is converted to a string or so. Upvote 0
Pedro Caldeira said: My code is a simple file.readlist Click to expand... With it you can only write/read simple strings. Maybe this is the cause if e.g. a map is converted to a string or so.
Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #5 so, to read a text file to a list but preserving its contents : Code: dim raf As RandomAccessFile raf.Initialize(somePath,someFile, False) dim TextList as list = raf.ReadObject(raf.CurrentPosition) raf.Close the code gets stuck in the raf.readobject line Upvote 0
so, to read a text file to a list but preserving its contents : Code: dim raf As RandomAccessFile raf.Initialize(somePath,someFile, False) dim TextList as list = raf.ReadObject(raf.CurrentPosition) raf.Close the code gets stuck in the raf.readobject line
Daestrum Expert Licensed User Longtime User Apr 6, 2018 #6 Have you an example of the file you are trying to read, it could be just a simple encoding error that is preventing you from reading it. Upvote 0
Have you an example of the file you are trying to read, it could be just a simple encoding error that is preventing you from reading it.
Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #7 Attached Attachments cashier.txt cashier.txt 826 bytes · Views: 622 Upvote 0
Daestrum Expert Licensed User Longtime User Apr 6, 2018 #8 The only way I could get it to write the same chars was to read the original as windows-1251, which makes me think this file is from a terminal type device. Code: Dim tr As TextReader Dim li As List li.Initialize tr.Initialize2(File.OpenInput("c:/temp","cashier.txt"),"windows-1251") li = tr.ReadList tr.Close For Each l As String In li Log(l) Next Last edited: Apr 6, 2018 Upvote 0
The only way I could get it to write the same chars was to read the original as windows-1251, which makes me think this file is from a terminal type device. Code: Dim tr As TextReader Dim li As List li.Initialize tr.Initialize2(File.OpenInput("c:/temp","cashier.txt"),"windows-1251") li = tr.ReadList tr.Close For Each l As String In li Log(l) Next
KMatle Expert Licensed User Longtime User Apr 6, 2018 #9 Pedro Caldeira said: dim raf As RandomAccessFile raf.Initialize(somePath,someFile, False) dim TextList as list = raf.ReadObject(raf.CurrentPosition) raf.Close Click to expand... Stuck means? Note: If you write encrypted, you need to read encrypted, too. Upvote 0
Pedro Caldeira said: dim raf As RandomAccessFile raf.Initialize(somePath,someFile, False) dim TextList as list = raf.ReadObject(raf.CurrentPosition) raf.Close Click to expand... Stuck means? Note: If you write encrypted, you need to read encrypted, too.
Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #10 KMatle said: Stuck means? Note: If you write encrypted, you need to read encrypted, too. Click to expand... it is not encrypted, it just has some weird chars in the begining of the lines Upvote 0
KMatle said: Stuck means? Note: If you write encrypted, you need to read encrypted, too. Click to expand... it is not encrypted, it just has some weird chars in the begining of the lines
KMatle Expert Licensed User Longtime User Apr 6, 2018 #11 Pedro Caldeira said: it just has some weird chars in the begining of the lines Click to expand... Please post the relevant code or an short example how you write and how you read it back (e.g. where is the text from?). I will take a look then. Upvote 0
Pedro Caldeira said: it just has some weird chars in the begining of the lines Click to expand... Please post the relevant code or an short example how you write and how you read it back (e.g. where is the text from?). I will take a look then.
Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #12 KMatle said: Please post the relevant code or an short example how you write and how you read it back (e.g. where is the text from?). I will take a look then. Click to expand... No I can read it correctly using @Daestrum solution with "windows-1251" encoding Upvote 0
KMatle said: Please post the relevant code or an short example how you write and how you read it back (e.g. where is the text from?). I will take a look then. Click to expand... No I can read it correctly using @Daestrum solution with "windows-1251" encoding
Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #13 However, no I notice something weird. I can read the file correctly. Then I filter some records and write the unfiltered ones to another list. when i log this last list lines, i get all the data in the log window, but when i write the list using a textwriter, i get an empty file. Code: Dim ListaCaixa as List Dim OutPutList as List dim tReader as TextReader tReader.Initialize2(File.OpenInput(WinRESTPath,"cashier.000"),"windows-1251") ListaCaixa = tReader.ReadList tReader.Close OutPutList.Clear For x=0 To ListaCaixa.Size -1 If ListaCaixa.Get(x) <> UnwantedData Then OutPutList.Add(ListaCaixa.Get(x)) log(ListaCaixa.Get(x)) ' Shows the correct data End If Next ' if I log the contents of OutPutList is correct dim tWriter as TextWriter tWriter.Initialize2(File.OpenOutput(WinRESTPath,"cashier.000",True),"windows-1251") tWriter.WriteList(OutPutList) tReader.Close cashier.000 is empty, size 0 Upvote 0
However, no I notice something weird. I can read the file correctly. Then I filter some records and write the unfiltered ones to another list. when i log this last list lines, i get all the data in the log window, but when i write the list using a textwriter, i get an empty file. Code: Dim ListaCaixa as List Dim OutPutList as List dim tReader as TextReader tReader.Initialize2(File.OpenInput(WinRESTPath,"cashier.000"),"windows-1251") ListaCaixa = tReader.ReadList tReader.Close OutPutList.Clear For x=0 To ListaCaixa.Size -1 If ListaCaixa.Get(x) <> UnwantedData Then OutPutList.Add(ListaCaixa.Get(x)) log(ListaCaixa.Get(x)) ' Shows the correct data End If Next ' if I log the contents of OutPutList is correct dim tWriter as TextWriter tWriter.Initialize2(File.OpenOutput(WinRESTPath,"cashier.000",True),"windows-1251") tWriter.WriteList(OutPutList) tReader.Close cashier.000 is empty, size 0
OliverA Expert Licensed User Longtime User Apr 6, 2018 #14 I'm pretty sure TextWriter is buffered, so until you call tWriter.Close, nothing may be written to disk (if all fits in the buffer). Alternatively, you can call tWriter.Flush to flush the buffers to disk (without closing the file). Upvote 0
I'm pretty sure TextWriter is buffered, so until you call tWriter.Close, nothing may be written to disk (if all fits in the buffer). Alternatively, you can call tWriter.Flush to flush the buffers to disk (without closing the file).
Pedro Caldeira Active Member Licensed User Longtime User Apr 6, 2018 #15 OliverA said: I'm pretty sure TextWriter is buffered, so until you call tWriter.Close, nothing may be written to disk (if all fits in the buffer). Alternatively, you can call tWriter.Flush to flush the buffers to disk (without closing the file). Click to expand... my bad !! I noticed that i was closing tReader instead of tWriter Last edited: Apr 6, 2018 Upvote 0
OliverA said: I'm pretty sure TextWriter is buffered, so until you call tWriter.Close, nothing may be written to disk (if all fits in the buffer). Alternatively, you can call tWriter.Flush to flush the buffers to disk (without closing the file). Click to expand... my bad !! I noticed that i was closing tReader instead of tWriter