JavaのFileInputStream

日付:2020年1月15日

機能:入力ストリーム内のJavaファイル

IDE:のIntelliJ IDEA

package testDemo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

public class Test {

    public static void main(String[] args) throws IOException {
        //字节数组,临时存放读取的字节
        byte[] result = new byte[100];
        //文件实例对象
        File file = new File("D:\\java_workstation\\zpc.txt");
        //文件输入流,建立流通道
        FileInputStream fileInputStream = new FileInputStream(file);
        //一次读取100字节,临时保存在result数组中
        int flag = fileInputStream.read(result,0,100);
        //读取的字节数不为0
        while (flag>0)
        {
            //转换成字符串
            String out = new String(result,0,flag);
            System.out.println(out);
            //继续读取
            flag = fileInputStream.read(result,0,100);
        }
    }
}

公開された76元の記事 ウォンの賞賛2 ビュー2128

おすすめ

転載: blog.csdn.net/weixin_43476969/article/details/103988689