package com.app;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class A1 {
public static void main(String[] args) {
A1 a1 = new A1();
String filePath = "D:/abc.txt" ;
String reslut = a1.readFile( filePath ) ;
System.out.println( reslut );
}
public String readFile( String filePath ){
FileInputStream fis=null;
String result = "" ;
try {
fis = new FileInputStream( filePath );
int size = fis.available() ;
byte[] array = new byte[size];
//4.把数据读取到数组中;
fis.read( array ) ;
result = new String(array);
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}finally{
if ( fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result ;
}
}
io流 FileInputStream类的使用:读取文件内容
最新推荐文章于 2024-08-17 23:23:57 发布