java代码流类

总结:读取到的是字节型转换成字符串。

  

package com.c2;

import java.io.*;

public class tkrp {
	public static void main(String[] args) throws IOException {
		File F = new File("fsa.txt");
		FileInputStream fis = new FileInputStream(F);// 以字节流形式读取文件
		BufferedInputStream buf = new BufferedInputStream(fis);// 以缓冲读取文件字节
		BufferedInputStream bb = new BufferedInputStream(System.in);//
		byte[] b1 = new byte[1024];
		byte[] b2 = new byte[1024];
		int num1 = buf.read(b1);// 将文件读取数据放入字节数组放在b1内,num1为读取的字节个数
		String str1 = new String(b1, 0, num1);// b1代表数组,o代表起始位置,num1代表字节个数/将
		// 字节数组转换成字符串,
		System.out.println(str1);
		int num2 = buf.read(b2);// 将读取的数据放在数组b2内,num2为读取字节个数
		String str2 = new String(b2, 0, num2);
		System.out.println(str2);

	}
}

  

原文地址:https://www.cnblogs.com/langlove/p/3418833.html