/*
* 2017/7/29
* 演示FileInPutStream类的使用
* 读文件
*/
package com.test5;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File file=new File("e:\\hsp.txt");
FileInputStream fis =null;
try {
fis =new FileInputStream(file);
//定义一个字节数组,相当于缓存
byte []bytes =new byte[1024];
int n=0;
while ((n=fis.read(bytes))!=-1) {
String s = new String(bytes,0,n);
System.out.println(s);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
//关闭文件流
try {
fis.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
FileInPutStream类的使用
最新推荐文章于 2024-08-14 11:38:52 发布