473,671 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading UTF data from c#

We created a unicode file using java application. It usesmethods like writeUTF(), writeInt() of java.io.DataOut putStreamclass to write the content of the file. We are able to read datausing java.io.DataInp utStream.readUT F() method. It's workingwell in java environment.

When we tried to read the above unicode file in .net environment.We received junk content not the original content.

Actually we tried a sample program in c# and usedSystem.Text .UTF8Encoding(t rue) option also. Any help highlyappreciat ed.

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>VGTUU+5aHEi NrMv6ZYlwRA==</Id>
Nov 16 '05 #1
3 8430
Sivaraj G via .NET 247 <an*******@dotn et247.com> wrote:
We created a unicode file using java application. It uses methods
like writeUTF(), writeInt() of java.io.DataOut putStream class to
write the content of the file. We are able to read data using
java.io.DataInp utStream.readUT F() method. It's working well in java
environment.

When we tried to read the above unicode file in .net environment. We
received junk content not the original content.

Actually we tried a sample program in c# and used
System.Text.UTF 8Encoding(true) option also. Any help highly
appreciated.


writeUTF first writes a pair of bytes to give the number of bytes to
follow. Those aren't UTF-8 characters, but .NET would be expecting them
to be.

Effectively, writeUTF and readUTF are only designed to work with
DataInputStream/DataOutputStrea m. You can probably read that pair of
bytes before reading the rest, but it's not ideal. If you're just
creating a text file in Java, I suggest you use OutputStreamWri ter
wrapped round a FileStream, and specify UTF-8 as the encoding. If
you're writing a file with mixed binary and text data, you need to make
sure you know *exactly* what you're writing, and then read it very
carefully from the other platform.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hello, Sivaraj!

Here is a block of code that might help (or give some ideas),
if I understood you correctly:
string
s=string.Empty,
path="c:\file.t xt", //... or whatever file you'll be using
NewLine=string. Empty; //this variable doesn't have to be initialized, but
it is a good habit

System.IO.Strea mReader MyStreamReader=
new System.IO.Strea mReader(path, System.Text.Enc oding.UTF8);

while((NewLine= MyStreamReader. ReadLine())!=nu ll)
s+=NewLine+"\r\ n";

MyStreamReader. Close();

//Now do something with 's'

Regards

You wrote on Fri, 06 Aug 2004 06:51:09 -0700:

SGN> When we tried to read the above unicode file in .net environment. We
SGN> received junk content not the original content.

SGN> Actually we tried a sample program in c# and used
SGN> System.Text.UTF 8Encoding(true) option also. Any help highly
SGN> appreciated.

SGN> -----------------------
SGN> Posted by a user from .NET 247 (http://www.dotnet247.com/)
With best regards, Nurchi BECHED.
Nov 16 '05 #3
Nurchi BECHED <nu****@telus.n et> wrote:
Here is a block of code that might help (or give some ideas),
if I understood you correctly:
string
s=string.Empty,
path="c:\file.t xt", //... or whatever file you'll be using
NewLine=string. Empty; //this variable doesn't have to be initialized, but
it is a good habit
I disagree on that point - if an assignment isn't required because
there'll be another assignment before the first "read" of the variable,
I'd rather the extraneous assignment isn't present in the first place.
It implies that the assigned value has some purpose, when it doesn't.
System.IO.Strea mReader MyStreamReader=
new System.IO.Strea mReader(path, System.Text.Enc oding.UTF8);

while((NewLine= MyStreamReader. ReadLine())!=nu ll)
s+=NewLine+"\r\ n";
That's a horrible way of building up a string. Use StringBuilder
instead.

In this case though, just MyStreamReader. ReadToEnd() would be a better
solution still.
MyStreamReader. Close();


You should use a using statement instead - that way if an exception is
thrown, the StreamReader still gets disposed.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

2
3021
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem when reading out the data into the PHP variables / array. It should be displaying the information out in the following way, using the PHP array: n_date, n_headline, n_summarytext, n_fulltext
0
3581
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it is written ( commented out in code) then it reads in OK. However, when I move the code to the right place ( as shown here) it throws an IO exception. Both the Filter class and it's constituent class implement Serializable and it would seem the...
1
6750
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but listen up; Reports, the way I look at them, all present data downwards, in this way; TITLE data
6
3785
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
6
5262
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
10
8349
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the delivery of Travis Oliphant's NumPy manual, I have a quick question (hopefully) regarding how to read in Fortran written data. The data files are not binary, but ASCII text files with no formatting and mixed data types (strings, integers,...
5
14983
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing and why I have to do it. Hopefully someone has a suggestion... Alright, so I'm using a gps-simulation program that outputs gps data, like longitude, lattitude, altitude, etc. (hundreds of terms, these are just the well known ones). In the newer...
4
2099
by: Shark | last post by:
Hi, I need a help. My application reads data from COM port, this data is then parsed and displyed on: 1. two plotters 2. text box. I'm using Invoke method to update UI when new data is received (through delegate).
13
3698
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file consists of structures of type---- struct record { int acountnum; char name; float value;
6
3524
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features to an old program that I wrote in delphi and it's a good opportunity to start with c++.
0
8397
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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
8599
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
7439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
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
4225
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...
1
2813
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.