package com.test;
import java.io.IOException;
import java.io.InputStream;
public class Test {
//java中\r,\n,\r\n,\n\r的区别,疑问?
public static void main(String[] args) throws IOException{
System.out.print("1----->\r5678test");
System.out.print("2----->\n");
System.out.print("3----->\n\r");
System.out.print("4----->\r\n");
System.out.print("5----->");
System.out.print("yes");
System.out.print("hello\r\n666");
System.out.print("hi777");
System.out.print("ok\n\r88");
System.out.print("go1\n99");
System.out.print("go2\r55");
System.out.print("go3\r44");
System.out.print("go4\n33");
System.out.print("go5\n\r22");
System.out.print("go6");
System.out.print("aaa");
// \f是换页符
System.out.println("qwe\fabc");
// 使用System.getProperty("line.separator")来获取当前OS的换行符
System.out.print(System.getProperty("line.separator"));
testCarriageReturnAndNewLine();
}
public static void testCarriageReturnAndNewLine() throws IOException {
InputStream in = System.in;
StringBuilder sb = new StringBuilder();
int ch = 0;
while ((ch = in.read()) != -1) {
if (ch == '\r') {
System.out.println("\\r");
}
if (ch == '\n') {
System.out.println("\\n");
}
sb.append((char) ch);
System.out.println("数据有:" + sb.toString());
System.out.println("长度为:" + sb.length());
}
}
}
java中\r,\n,\r\n,\n\r的区别,疑问?
猜你喜欢
转载自blog.csdn.net/czh500/article/details/104989784
今日推荐
周排行