先说答案:是"\r\n"
测试例子:文档为"abced回车"
public class test_01 {
public static void main(String[] args) throws Exception{
method_03();
}
private static void method_03() throws Exception{
FileInputStream fileInputStream = new FileInputStream("C:\\Users\\10167\\Desktop\\test.txt");
FileChannel fileChannel = fileInputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(7);
int readLine = fileChannel.read(byteBuffer);
for (int i = 0 ; i < byteBuffer.limit() ; i ++){
System.out.print(byteBuffer.get(i)+" ");
}
System.out.println(readLine);
//byteBuffer.clear();
readLine = fileChannel.read(byteBuffer);
System.out.println(readLine);
byteBuffer.clear();
readLine = fileChannel.read(byteBuffer);
System.out.println(readLine);
}
}
输出为:
97 98 99 100 101 13 10
7
0
-1
可以查看ascii的代码13为"\r",10为"\n"。