当我使用 NIO2 通道读取此字符串时:
È bla bla bla
我在控制台中得到了这个:
? bla bla bla
我想知道如何设置字符集,当代码是这样的:
RandomAccessFile aFile = new RandomAccessFile("in.txt", "rw");
FileChannel inChannel = aFile.getChannel();
ByteBuffer buf = ByteBuffer.allocate(48);
int bytesRead = inChannel.read(buf);
while (bytesRead != -1) {
System.out.println("Read " + bytesRead);
buf.flip();
while(buf.hasRemaining()){
System.out.print((char) buf.get());
}
buf.clear();
bytesRead = inChannel.read(buf);
}
aFile.close();
我想设置这样的东西:
StandardCharsets.ISO_8859_1