欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

io之FileInputStream

程序员文章站 2022-05-28 16:51:17
...
package com.laien.io;

import java.io.FileInputStream;
import java.io.InputStream;

/**
 * 从硬盘中把数据读到内存中,谓之INPUT
 * @author Administrator
 *
 */
public class InputStreamTest {

	public static void main(String[] args) throws Exception {
		InputStream fileInputStream = new FileInputStream("D:/test.txt");

		byte[] buffer = new byte[200];
		//每次读到的长度
		int length = 0;
		//流写下到buffer中,从0开始,每次最多读200字节,返回读取的长度,读取完成后,长度会返回-1
		while (-1 != (length = fileInputStream.read(buffer, 0, 200))) {
			String str = new String(buffer, 0, length);
			
			System.out.print(str);
		}
		
		fileInputStream.close();
	}

}

 

相关标签: io FileInputStram