1. 程式人生 > >【FileInputStream類:位元組輸入流】

【FileInputStream類:位元組輸入流】

package test;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author shusheng
 * @description
 * @Email [email protected]
 * @date 2018/11/9 16:16
 */
public class FileInputStreamDemo1 {
    /*
     *位元組輸入流操作步驟:
     *A:建立位元組輸入流物件
     *B:呼叫read()方法讀取資料,並把資料顯示在控制檯
     *C:釋放資源
     *
     *讀取資料的方式:
     *A:int read():一次只能讀一個位元組
     *B: int read(byte[] b):一次讀取一個位元組陣列
     
*/ public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("fos.txt"); int by = 0; while((by=fis.read())!=-1){ /**不能識別漢字*/ System.out.println((char)by); } } }