• IO异常处理


    import java.io.*;
    public class StandardIO {
        public static void main(String[] args) {
            try {/*先使用System.in构造InputStreamReader,再构造BufferedReader*/
                BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
                System.out.print("Enter a string:");
                System.out.println(stdin.readLine());
                System.out.print("Enter an integer:");
                int number1 = Integer.parseInt(stdin.readLine());/*将字符串解析为带符号的十进制整数*/
                System.out.println(number1);
                System.out.print("Enter a double:");
                double number2 = Double.parseDouble(stdin.readLine());
                System.out.println(number2);
            } catch(IOException e){System.err.println("IOException");}
        }
    }
    //Char_Ascii.java
    public class Char_Ascii {
        public static void main(String[] args) {
            int ascii_value;
            char char_value = '0';
            for(int i = 1;i<=10;i++)
            {
                char_value = (char)System.in.read();
                ascii_value = (int)char_value;
                System.out.println(char_value + "<== =>" + ascii_value);
            }
        }
    }

    在Char_Ascii.java中编译会出现未捕获的IO异常错误

    java中System.out和System.err 已被封装成PrintStream对象,因此具有强大的输出的功能,但System.in却仍然是原始的InutStream,需要在使用的时候进行封装

    转载来自:http://www.cnblogs.com/gride-glory/p/7682670.html

  • 相关阅读:
    jwt原理
    图书管理系统后端
    图书管理系统前端
    图书管理前端页面
    Linux多任务: exec 和fork()的联用
    CPU 字长与存储器位宽不一致处理
    关键字volatule
    linux C 中断程序:利用队列保存中断类型
    Linux下的Make与Makefile
    C :assert() 的用法
  • 原文地址:https://www.cnblogs.com/lls1350767625/p/7801861.html
Copyright © 2020-2023  润新知