पढ़ना मैं निम्नलिखित कोड है:FileChannel साथ एक ASCII फ़ाइल और 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();
}
लेकिन पात्रों को प्रदर्शित हो रहा है। क्या यूनिकोड वर्णों का उपयोग कर जावा के साथ इसका कुछ संबंध है? मैं इसे कैसे ठीक करूं?
यदि आप प्रत्येक चरित्र को अलग से प्रिंट करने से बचना चाहते हैं, तो आप 'buf.rewind()' के बजाय 'buf.flip() 'का उपयोग कर सकते हैं और पास कर सकते हैं पूरे chbuf 'System.out.print()' के लिए – hertzsprung