473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

StreamReader/StreamWriter problem

I have a problem where some data is being eliminated.

The problem is that the data contains signed numeric fields (the low-order
byte of a negative number uses the first 4 bits as a sign and the last 4
bits as the low-order digit. This produces byte values higher than X'7F'. To
be more specific these values are hexadecimal X'B0' through X'B9'. It
appears the program is eliminating any byte values greater than X'7F', thus
shortening the record. I am using StreamReader and StreamWriter for the
I/O.

Is it a possibility that the data contained in the file is written in UTF-7
and the code needs to be adjusted to UTF-8??? Here is how I am opening the
input file:

Public Function ReadInFile() As Integer
Dim reader As StreamReader
Dim output As String = String.Empty

Try
reader = File.OpenText(inFileName)
output = String.Format("Input file {0} is opened successfully",
inFileName)
Logger.Log(output)
Dim line As String = reader.ReadLine()
While Not line Is Nothing
Dim record As CGIRecordIn = New CGIRecordIn(line)
inRecords.Add(record)
line = reader.ReadLine()
End While

Catch ex As Exception
output = String.Format("Failed reading {0}", inFileName)
Logger.Log(output)
Finally
reader.Close()

End Try
ReadInFile = inRecords.Count
output = String.Format("Read {0} valid records from input file",
ReadInFile)
Logger.Log(output)
End Function

Here is how I am opening the output file:

Public Sub WriteOutFile()
Dim recordOut As CGIRecordOut
Dim writer As StreamWriter
Dim output As String
Try
writer = File.CreateText(outFileName)
output = String.Format("Output file {0} is opened successfully
for writing", outFileName)
Logger.Log(output)

For Each recordOut In outRecords
recordOut.Build()
writer.WriteLine(recordOut.Rec)
Next

Catch ex As Exception
output = String.Format("Failed writing to {0}", outFileName)
Logger.Log(output)
Finally
writer.Close()
End Try

Logger.Log("Finished writing output file")
End Sub

I am not too clear as to the parameter that is needed to tell VB.NET that
the file is being opened as UTF-8 and written in the same format. Any help
would be greatly appreciated.

Thanks!

Nov 17 '06 #1
2 3081

"Thelonious Monk" <th***************@hotmail.comwrote in message
news:ea**************@TK2MSFTNGP06.phx.gbl...

Might want to look into

' StreamReader(filename, encoding)
Dim reader As New StreamReader(inFilename, System.Text.Encoding.UTF8)

and

' StreamWriter(filename, append?, encoding)
Dim writer As New StreamWriter(outFilename, False,
System.Text.Encoding.UTF8)

That might do the trick. I apologize for being too darn tired to test right
now...
Nov 17 '06 #2
Thanks, Mike C#. Looks like it worked. Thanks again for your help.

"Mike C#" <xy*@xyz.comwrote in message
news:8F***************@newsfe08.lga...
>
"Thelonious Monk" <th***************@hotmail.comwrote in message
news:ea**************@TK2MSFTNGP06.phx.gbl...

Might want to look into

' StreamReader(filename, encoding)
Dim reader As New StreamReader(inFilename, System.Text.Encoding.UTF8)

and

' StreamWriter(filename, append?, encoding)
Dim writer As New StreamWriter(outFilename, False,
System.Text.Encoding.UTF8)

That might do the trick. I apologize for being too darn tired to test
right now...

Nov 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joecx | last post by:
Using vb.net, I am using Streamreader to read a text file and searching for a line to delete, the I close the file and open it as a streamwriter so I can put the new file back to disk without the...
4
by: Jaroslav Jakes | last post by:
Hi, please help. Sounds so simple. We receive textfiles (customer orders) as e-mail attachment. These textfiles contain a simple structure of orders, like: custno, itemno, qty, text Since...
1
by: Simon Abolnar | last post by:
I would like to read one text file with StreamReader and write it to other file with StreamWriter: Do Until OldFile.Peek=-1 TextLine=OldFile.ReadLine NewFile=WriteLine(TextLine) Loop ...
5
by: ramendra | last post by:
Hello there, I am having some problem with using StreamWriter object in aspnet application. The thing is when i use the streamwriter in an aspnet page the code gets executed fine but its...
1
by: Stephen | last post by:
Hi, I am reading a file (c:\address.txt) using streamreader and I want to make changes to a line in the file and save it. will there be a locking issue if I read and write to the samefile...
15
by: Zytan | last post by:
I have installed the Visual C# 2005 Code Snippets, and the snippets for file handling use StreamReader and StreamWriter, instead of System.IO.File.*. VB 2005 code snippets don't use these. Why...
10
by: SpecialKay | last post by:
i got a nice problem here: my page recieves a request, it then sends a request back to the other server with all of the same params as the orignal requess, and waits for a responce the responce...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.