읽기 나는 다음과 같은 코드를 가지고 :아스키되는 FileChannel와 파일 ByteArrays
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();
}
을하지만 문자가 표시 얻을의. 이것이 유니 코드 문자를 사용하는 Java와 관련이 있습니까? 이 문제를 어떻게 해결합니까?
각 문자를 개별적으로 인쇄하지 않으려면'buf.rewind()'대신'buf.flip()'을 사용하고 pass 전체 chbuf를'System.out.print()' – hertzsprung