这个帖子也算是早前我的这个帖子的补完吧!《Windows中Java中的回车与换行 》。代码还是一样的:
import java.io.*; public class Test { public static void main(String args[]){ try{ byte[] b = new byte[2]; int c = System.in.read(b); System.out.println("读入的字节数:"+ c); for(byte d : b) System.out.println(d); }catch(IOException e){ e.printStackTrace(); } } }
输出当然是不一样:
读入的字节数:1 10 0
也就是说Linux下面的“回车”就是“换行”,也就是'\n'。这和Windows是不一样的,在Windows里“回车”是'\r\n'的组合。