the code:
-----------------
static public String loadFile(String s) throws Exception {
DataInputStream isr = new
DataInputStream(LanguageLoader.class.getResourceAsStream(s));
return isr.readUTF();
}
-----------------
I try with ansi file, with UC2 file and UTF-8 file.
Always throws EOF.
Every time, the contents of file are:
-----------------
english=english
german=german
italiano=italiano
-----------------
what is the problem?
thanks!
hiwa - 04 Jan 2006 01:01 GMT
Try using BufferedReader and its readLine() method.
In my impression gotten from past experiences, DataInputStream
and its readUTF() method are semi-deprecated APIs.
They are not simpile nor easy to use and can often bring troubles.
Read the API documentation for DataInput#readUTF() method.
Be amazed at its complicatedness and awkwardness of the
description.
Chameleon - 04 Jan 2006 11:14 GMT
> Try using BufferedReader and its readLine() method.
> In my impression gotten from past experiences, DataInputStream
[quoted text clipped - 3 lines]
> Be amazed at its complicatedness and awkwardness of the
> description.
yes but I forgot to say that my app runs on mobiles and the api is simpler.
Maybe if I try loop with getChar?
Roedy Green - 04 Jan 2006 01:05 GMT
On Wed, 04 Jan 2006 00:55:08 +0200, Chameleon
<cham_gss@hotmail.NOSPAM.com> wrote, quoted or indirectly quoted
someone who said :
>I try with ansi file, with UC2 file and UTF-8 file.
>Always throws EOF.
Someone just made this same mistake in a another post.
readUTF is NOT for reading UTF-16 or UTF-8 text files. It is for
reading binary format files containing counted strings with binary
lead counts.
you want a FileReader using explicit UTF-8 encoding.
see http://mindprod.com/applets/fileio.html
for the sample code.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Chris Uppal - 04 Jan 2006 12:03 GMT
> I try with ansi file, with UC2 file and UTF-8 file.
> Always throws EOF.
Despite its name, DataInputStream.readUTF() does NOT read UTF-8 or any other
Unicode format.
If you want to read Unicode text, use a Reader with an appropriate character
encoding.
-- chris
Chameleon - 04 Jan 2006 16:19 GMT
> the code:
> -----------------
[quoted text clipped - 16 lines]
> what is the problem?
> thanks!
with this code I can read UC-16 text files BUT with big endian char
storing (I created a php script for precompile convertion from little to
big endian)
------------------------------
static public String loadFile(String s) throws Exception {
DataInputStream isr = new
DataInputStream(LanguageLoader.class.getResourceAsStream(s));
s = "";
int z = isr.available() / 2;
for(; z > 0; z--)
s += isr.readChar();
return s;
}
------------------------------
the problem is that I run readChar() inside a loop and I don't trust
speed of such operations in Java (specially java for mobiles)