Java核心类库-IO-扫描器(Scanner)数据流

Java.util.Scanner类:扫描器类,表示输入操作

  存在的方法:xxx拜年是数据类型,如byte,int,boolean等

  Xxx  nextXxx():获取下一个该类型的数据

1 public static void main(String[] args) throws FileNotFoundException {
2 
3         Scanner sc = new Scanner(new File("stream.txt"),"UTF-8");
4         while (sc.hasNextLine()){
5             String line = sc.nextLine();
6             System.out.println(line);
7         }
8         sc.close();
9     }

 

数据流,提供了可以读/写任意数据的方法

DataOutStream:提供了writeXxx(xxx value)方法

DataInputStream:提供了readXxx()方法

注意:writerXxx和readXxx必须要对应起来,writeByte写出的数据,此时只能使用readByte读取回来

posted @ 2017-05-24 22:28  wenxudong  阅读(254)  评论(0编辑  收藏  举报