今天看到一行java的一行代码,String newLine = System.getProperty("line.separator");看过之后有点晕,到网上查过之后,才知道它与‘\n’有相同的功能,下面是测试代码:
StringBuffer buf=new StringBuffer();
buf=buf.append("sun");
buf=buf.append(System.getProperty("line.separator"));
buf=buf.append("sun");
//就相当于换行符‘\n’
buf=buf.append(System.getProperty("line.separator"));
buf=buf.append("sun");
System.out.println(buf.toString());
结果是:
sun
sun
sun
但不知这两种有何区别,不过要显示水平的话这可倒是个卖点啊