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;
---------------------------------
IchBin - 01 Jan 2006 17:56 GMT
> I want a small piece of code (for mobile) which reads entile file
> "file.txt" from JAR and store it to a string.
[quoted text clipped - 11 lines]
> 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-)
Roedy Green - 02 Jan 2006 14:56 GMT
>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
you don't need the zip stuff to get an a resource. getResource and
getResourceAsStream do that for you.
getResource gives you an URL. getResourceAsStream gets you an
InputStream.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Svante Frey - 02 Jan 2006 13:27 GMT
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.
Roedy Green - 02 Jan 2006 14:55 GMT
On Sun, 01 Jan 2006 16:29:26 +0200, Chameleon
<cham_gss@hotmail.NOSPAM.com> wrote, quoted or indirectly quoted
someone who said :
> DataInputStream dis = new
>DataInputStream(LanguageLoader.class.getResourceAsStream("file.txt"));
> s = dis.DataInputStream.readUTF();
DataInputStream is for binary files where strings have preceding
length counts. You want a Reader with explicit encoding.
See http://mindprod.com/applets/fileio.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.