javaSE InputStream, FileInputStream, 文件读取。 read()读取下一个字节


Demo.java:

package cn.xxx.demo;

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

public class Demo {
	public static void main(String[] args) throws IOException{
		FileInputStream fis = new FileInputStream("c:\\a.txt");  // 创建读入流对象。
		int oneByte = 0;
	
		while( (oneByte = fis.read()) != -1){  // read() 读取下一个字节 byte=>int。   返回-1表示读到结尾。
			System.out.print((char)oneByte);
		}
    	
		fis.close();  //关闭资源
	}
}



猜你喜欢

转载自blog.csdn.net/houyanhua1/article/details/80703254
今日推荐