1. 程式人生 > >java之IO流

java之IO流

class stream puts read void col abc div pan

 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流