zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    如何进行函数式编程
    HTML文本格式化
    非模态对话框的创建及注意事项
    中国第一代程序员列传
    野指针
    缓冲区溢出攻击
    windows全部启动项
    HTML 样式
    Volatile关键字
    HTML基本标签
  • 原文地址:https://www.cnblogs.com/yangyongqian/p/5153301.html
Copyright © 2011-2022 走看看