<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">package com.hfxt;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
//输入流 读取文件
public class FileInputStreamDemo {
public static void main(String[] args) {
FileInputStream fs = null;
try {
fs = new FileInputStream("F:/fangchen/test.txt");
System.out.println("可以读到的字节数为:"+fs.available());
int data;
//如果输入流不读到末尾就一直读取
while((data=fs.read())!=-1){
System.out.print((char)data);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
//关闭输入流
try {
fs.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
</span></strong>
FileInputStream(输入流)字节流
最新推荐文章于 2023-09-18 16:42:05 发布