read file.txt in unicode

C

Chameleon

I want a small piece of code (for mobile) which reads entile file
"file.txt" from JAR and store it to a string.
"file.txt" has unicode format (2 bytes for every char)

The following code does not work:
---------------------------------
String s = null;
try {
DataInputStream dis = new
DataInputStream(LanguageLoader.class.getResourceAsStream("file.txt"));
s = dis.DataInputStream.readUTF();
} catch(Exception e) {
}
return s;
---------------------------------
 
I

IchBin

Chameleon said:
I want a small piece of code (for mobile) which reads entile file
"file.txt" from JAR and store it to a string.
"file.txt" has unicode format (2 bytes for every char)

The following code does not work:
---------------------------------
String s = null;
try {
DataInputStream dis = new
DataInputStream(LanguageLoader.class.getResourceAsStream("file.txt"));
s = dis.DataInputStream.readUTF();
} catch(Exception e) {
}
return s;
---------------------------------

Not sure if this helps but there are a few examples in the The Java
Developers Almanac 1.4

To find which file entry in zip file...
*e454. Listing the Contents of a ZIP File*
http://javaalmanac.com/egs/java.util.zip/ListZip.html?l=rel

*e455. Retrieving a Compressed File from a ZIP File*
http://javaalmanac.com/egs/java.util.zip/GetZip.html?l=rel

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
S

Svante Frey

Unicode can be encoded in several different ways. "two bytes per char"
sounds like UTF-16 or UCS-2. The readUTF() function reads UTF-8
encoding (which uses 1-4 bytes for every Unicode character), so it
can't be used to read an UTF-16 encoded file. See
http://en.wikipedia.org/wiki/Unicode for more info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top