首页 > 编程知识 正文

InputStream 一个字节一个字节的读取,getchar只能读取一个字节

时间:2023-05-03 22:10:17 阅读:222594 作者:819

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[lendydzp=(byte) temp;
}
in.close();
System.out.println("读取到的内容是:"+new String(b));
}


}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。