• IO流(读取键盘录入)


     1 package com.yyq;
     2 import java.io.*;
     3 /*
     4  * 字节流 FileInputStream
     5  *     FileOutputStream
     6  *     BufferedInputStream
     7  *     BufferedOutPutStream
     8  */
     9 /*
    10  * 读取键盘录入: 
    11  *   system.out: 对应的是标准的输出设备,控制台
    12  *   system.in: 对应的是标准的输入设备,键盘 
    13  */
    14 /*
    15  * 需求: 通过键盘录入数据,录入一行数据打印,
    16  * 录入over 停止。
    17  */
    18 public class TransStreamDemo {
    19 
    20     public static void main(String[] args) throws IOException {
    21         // TODO Auto-generated method stub
    22         //System.in 是字节流 对应的类型是inputStream
    23         InputStream in = System.in;
    24         // 此处的read 方法是一个阻塞式方法,等待我的键盘录入
    25         // 被提升 这是键盘录入
    26         StringBuilder sb = new StringBuilder();
    27         while(true){
    28             int ch = in.read();
    29             if(ch =='
    '){
    30                 continue;
    31             }
    32             if(ch=='
    '){
    33                 String s = sb.toString();
    34                 if("over".equals(s)){
    35                     break;
    36                 }
    37                 System.out.println(s.toUpperCase());
    38                 sb.delete(0,sb.length());
    39             }
    40             else{
    41                 sb.append((char)ch);
    42             }
    43         }
    44     }
    45 
    46 }
  • 相关阅读:
    delphi消息发送字符串
    Delphi2007 在Win10 下运行报错 Assertion failure
    python 定时器
    python 直接赋值 深浅拷贝
    python 闭包
    python 对象
    c++ sizeof和strlen
    c++入门笔记(一)
    python实现四种排序逻辑与代码
    webrtc autotest
  • 原文地址:https://www.cnblogs.com/yangyongqian/p/5153301.html
Copyright © 2020-2023  润新知