您的位置:首页 > 其它

InputStream 一个字节一个字节的读取

2016-06-05 12:08 169 查看
package chap10.sec03;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.InputStream;

public class Demo4 {

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File file =new File("D:/测试文件.txt");
InputStream in=new FileInputStream(file);//实例化FileInputStream
int fileLength=(int)file.length();
byte b[]=new byte[fileLength]; 
int temp=0;
int len=0;
while((temp=in.read())!=-1){
b[len++]=(byte) temp;
}
in.close();
System.out.println("读取到的内容是:"+new String(b));
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: