From: Hakan on

When I read files with a RandomAccessFile, I get them in Unicode
format. I have been trying, but can't really use that with the rest of
my syntax, like for example searching for character patterns et.c. . How
can I convert it to characters in the English language?

Regards,

H�kan Lane


--
Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet
Die Signatur l��t sich nach Belieben anpassen ;-)
From: Arne Vajhøj on
On 08-04-2010 16:50, Hakan wrote:
> When I read files with a RandomAccessFile, I get them in Unicode format.
> I have been trying, but can't really use that with the rest of my
> syntax, like for example searching for character patterns et.c. . How
> can I convert it to characters in the English language?

In Java characters are unicode.

If you read bytes from your RandomAccessFile then you can convert
them to String using the appropriate String constructor.

Arne

From: Lew on
Hakan wrote:
>
> When I read files with a RandomAccessFile, I get them in Unicode format.
> I have been trying, but can't really use that with the rest of my
> syntax, like for example searching for character patterns et.c. . How
> can I convert it to characters in the English language?

<http://java.sun.com/javase/6/docs/api/java/io/InputStreamReader.html>
<http://java.sun.com/javase/6/docs/api/java/io/InputStreamReader.html#InputStreamReader(java.io.InputStream,
java.lang.String)>

Something like

Reader rdr = new InputStreamReader(
new FileInputStream( someFile ),
"UTF-8"
);

--
Lew
From: Arne Vajhøj on
On 08-04-2010 19:59, Lew wrote:
> Hakan wrote:
>> When I read files with a RandomAccessFile, I get them in Unicode
>> format. I have been trying, but can't really use that with the rest of
>> my syntax, like for example searching for character patterns et.c. .
>> How can I convert it to characters in the English language?
>
> <http://java.sun.com/javase/6/docs/api/java/io/InputStreamReader.html>
> <http://java.sun.com/javase/6/docs/api/java/io/InputStreamReader.html#InputStreamReader(java.io.InputStream,
> java.lang.String)>
>
> Something like
>
> Reader rdr = new InputStreamReader(
> new FileInputStream( someFile ),
> "UTF-8"
> );

You assume that RandomAccessFile is not a requirement ?

Arne

From: markspace on
Hakan wrote:
>
> When I read files with a RandomAccessFile, I get them in Unicode format.
> I have been trying, but can't really use that with the rest of my
> syntax, like for example searching for character patterns et.c. . How
> can I convert it to characters in the English language?


By Unicode I assume you mean the raw Unicode bytes.

What about:

RandomAccessFile raf =
new RandomAccessFile( new File( "test" ), "rw" );
byte[] buff = new byte[LEN];

raf.read( buff );
String s = new String( buff, "UTF-8" );

?

There are some "UTF-like" methods in RandomAccessFile, but the docs
admit the methods aren't complete and won't read full Unicode. This
method should be 100% Unicode compatible and easy to change to other
types of encoding too, should you need to in the future.


 | 
Pages: 1
Prev: MIDI
Next: What happened to J/Invoke?