java之IO流
Posted jiangjunwei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java之IO流相关的知识,希望对你有一定的参考价值。
1 public class Demo1_FileInputStream { 2 3 public static void main(String[] args) throws IOException { 4 //demo1(); 5 FileInputStream fis = new FileInputStream("a.txt"); // 内容为 abc 6 int x; 7 while((x = fis.read())!=-1) { 8 System.out.println(x); 9 } 10 } 11 12 public static void demo1() throws FileNotFoundException, IOException { 13 FileInputStream fis = new FileInputStream("a.txt"); // 内容为 abc 14 int x = fis.read(); // x = 97 15 System.out.println(x); // 当 文件中的内容读完后再读时 返回值为 -1 16 fis.close(); 17 } 18 19 }
以上是关于java之IO流的主要内容,如果未能解决你的问题,请参考以下文章
java基础之 IO 流(RandomAccessFile类)