readline.java

来自「用java编写的一些初级代码」· Java 代码 · 共 31 行

JAVA
31
字号
public class Readline { 
    public static void main(String args[]){ 
	byte buf[]=new byte[1024];
	String strInfo=null;
	int pos=0;
	int ch=0;
	System.out.println("enter info");
	while(true){
	    try{
		ch=System.in.read();}
	    catch(Exception e)
	    {	System.out.println(e.getMessage());}
	    switch (ch)
	    {
		case '\r':
		    break;
		case '\n':
		    strInfo=new String(buf,0,pos);
		    if(strInfo.equals("bye"))
			return;
		    else
			System.out.println(strInfo);
			pos=0;
			break;
		default:
		    buf[pos++]=(byte)ch;
    }
    }
    }
}  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?