473,666 Members | 2,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(i nFileName)
output = String.Format(" Input file {0} is opened successfully",
inFileName)
Logger.Log(outp ut)
Dim line As String = reader.ReadLine ()
While Not line Is Nothing
Dim record As CGIRecordIn = New CGIRecordIn(lin e)
inRecords.Add(r ecord)
line = reader.ReadLine ()
End While

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

End Try
ReadInFile = inRecords.Count
output = String.Format(" Read {0} valid records from input file",
ReadInFile)
Logger.Log(outp ut)
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(outp ut)

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

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

Logger.Log("Fin ished 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 3104

"Thelonious Monk" <th************ ***@hotmail.com wrote in message
news:ea******** ******@TK2MSFTN GP06.phx.gbl...

Might want to look into

' StreamReader(fi lename, encoding)
Dim reader As New StreamReader(in Filename, System.Text.Enc oding.UTF8)

and

' StreamWriter(fi lename, append?, encoding)
Dim writer As New StreamWriter(ou tFilename, False,
System.Text.Enc oding.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.comwro te in message
news:8F******** *******@newsfe0 8.lga...
>
"Thelonious Monk" <th************ ***@hotmail.com wrote in message
news:ea******** ******@TK2MSFTN GP06.phx.gbl...

Might want to look into

' StreamReader(fi lename, encoding)
Dim reader As New StreamReader(in Filename, System.Text.Enc oding.UTF8)

and

' StreamWriter(fi lename, append?, encoding)
Dim writer As New StreamWriter(ou tFilename, False,
System.Text.Enc oding.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
2422
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 line that I deleted. Can someone tell me how I can do this without having to close the file first before switching to streamwriter, because closing the file allows someone else to grab the file before I put the new information back. Thanks if any...
4
9368
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 these textfile are made on different systems, the field "text" causes some trouble.
1
348
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 Everything works OK, BUT in FEW lines of file, TextLine is "" althogh they are written correctly in New File ????? (I don't understand at all).
5
1261
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 terminating the session. I think this is a know issues. I have given full rights to the aspnet user over the directory in which the application tries to create a file and writes to that file, thanks, Ramendra
1
1451
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 simultaneously? Thanks, Stephen
15
7122
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 are they suggesting the use of these classes instead of the fundamental File methods? Are they better? I thought code snippets were supposed show things in the easy / simple way. What do you guys think? What should a beginner learn to do when...
10
3193
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 should be "Valid" or "Invalid" and then my pages sends back the orignal response witch is discarded. When i run on local.host everything works perfectly. I upload my files to the server, and run the page and it crashes at this line of code: ...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.