Das Lesen einer ASCII-Datei mit FileChannel und ByteArrays

Ich habe den folgenden code:

        String inputFile = "somefile.txt";
        FileInputStream in = new FileInputStream(inputFile);
        FileChannel ch = in.getChannel();
        ByteBuffer buf = ByteBuffer.allocateDirect(BUFSIZE);  //BUFSIZE = 256

        /* read the file into a buffer, 256 bytes at a time */
        int rd;
        while ( (rd = ch.read( buf )) != -1 ) {
            buf.rewind();
            for ( int i = 0; i < rd/2; i++ ) {
                /* print each character */
                System.out.print(buf.getChar());
            }
            buf.clear();
        }

Aber die Zeichen angezeigt bekommen ?'s ist. Hat das etwas zu tun mit Java mit Unicode-Zeichen? Wie kann ich das korrigieren?

InformationsquelleAutor Jake | 2008-09-18

Schreibe einen Kommentar