How can I read a file, which writen in german and saved in Uni-code format.
the text for example like following:
Instruktion f黵 Wort-Wort Stroop Deutsch
Hallo,
jetzt schauen wir mal, wie gut du lesen kannst.
In diesem Test siehst du immer zwei deutsche W鰎ter.
Das erste Wort erscheint etwas fr黨er als das zweite Wort auf dem Bildschirm.
The above text was save the file text.txt in Uni-code format
now I want read this file to a string.
How should I do?
[434 byte] By [
kaihua1a] at [2007-10-1 22:53:44]

Can someone give me ExampleCode, which solves this problem?
http://java.sun.com/docs/books/tutorial/essential/io/index.html http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedReader.html#readLine() http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileReader.html
mlka at 2007-7-15 13:52:49 >

The same way you would read any other text file. There is no GermanInputStreamReader(). As long as you know the encoding, that's not a problem. Do you know how to read text files generally?
// the following code I have used to read the text
String instructionSD;
File file = new File("instructionSD.txt");
if(file.canRead())
{
RandomAccessFile rafile = null;
try {
rafile = new RandomAccessFile(file, "r");
}
catch (FileNotFoundException ex) {
}
long length = 0L;
try {
length = rafile.length();
}
catch (IOException ex3) {
}
byte [] text = new byte[(int)length];
try {
rafile.read(text);
}
catch (IOException ex4) {
}
StringBuffer sb = new StringBuffer();
for(int i = 0; i<length; i++)
{
sb.append((char)text);
}
instructionSD = sb.toString();
}>
Ok, then please re-visit the links provided to you above (especially the first one with the tutorial). You want to use a Reader object (probably an InputStreamReader constructed on a FileInputStream). This will handle all the byte-to-character conversions for you.
hello mlk, JoachimSauer,I know how to read the file to a string, but the problem is that, the text now writen in German und save in Unicode format.I have tried the usual ways, but it do not work.Can you or someone else help me?
hello JoachimSauer,
I have even tried such code:
try
{
FileInputStream fis = new FileInputStream("instructionSD.txt");
// InputStreamReader isr = new InputStreamReader(fis);
char ch;
int i;
try
{
while ((i = fis.read() )!= -1)
{
ch = (char)i;
System.out.println(ch);
}
}
catch (IOException ex) {
}
}
catch (FileNotFoundException fnfe) {
System.err.println(fnfe);
}
but it also do not work.
[url= http://forum.java.sun.com/help.jspa?sec=formatting]Use code tags[/url]Never ignore exceptions.Use Readers for char data.
mlka at 2007-7-15 13:52:51 >

import java.io.*;
import javax.swing.JOptionPane;
public class Test {
public static void main( String argv[] ) throws Throwable {
BufferedReader br =
new BufferedReader(
new InputStreamReader(new FileInputStream("test.txt"),
"unicode"));String s = null;
StringBuffer sb = new StringBuffer();
while( ( s = br.readLine() ) != null ) {
sb.append( s );
System.out.println( s );
}
br.close();
JOptionPane.showMessageDialog( null, sb.toString() );
}
}
mlka at 2007-7-15 13:52:52 >

Hello mlk,I try it, thanks.
Hello mlk,you are great!!!Your code do work. Thanks a lot.
Hello JoachimSauer,thank you too for your help.
Hello, mlk, JoachimSauer,I have total 25 points, now I have just 15 points rest. Haha.But it is really very pleasure to meet you.