标准输入输出
1.在java中,输入需要引入“异常处理”机制,
格式一:在main方法后用throws子句抛出 IOException,
形如:public static void main(String arg[]) throws java.io.IOException
格式二:在程序的第一行导入 java.io.* 包,然后在main方法首部的末尾加上throws IOException
形如: import java.io.*;
public class test{
public static void main(String arg[]) throws IOException{
...... }
}
对输入引入‘异常处理’的思考:
把输入当成一个打断当前操作的 异常,是因为程序被中断,而一般对异常的理解也就是打断当前的操作,执行优先级较当前操作高的作业或进程,
这时 输入也当为异常 也可以理解了。
2.read 方法有三种格式:
(1)System.in.read(); //从键盘输入一个字符
(2)System.in.read(byte[] b); //从键盘输入多个字节,存于字节数组中
实例: byte b[] = new byte[16];
System.in.read(b);
注:此时读取该应该使用
System.out.write(b);
(3)System.in.read(byte[] b,int off ,int len)
此处不理解。留待后面细看。