package java_learning;
import java.io.*;
public class ReadFromFile {
public static void main(String[] args) throws IOException {
String fileName="F:"+File.separator+"hello.txt";
File f = new File(fileName);
InputStream in = new FileInputStream(f);
//byte[] b = new byte[(int)f.length()];
byte[] b = new byte[1024];
int count = 0;
int temp =0;
while((temp = in.read()) != -1){//当读到文件末尾的时候会返回-1
b[count++] = (byte)temp;
}
// int len=in.read(b);
in.close();
System.out.println("文件长度为:"+f.length());
System.out.println("读数据长度为:"+count);
System.out.println(new String(b, 0, count));
}
}
ReadFromFile
最新推荐文章于 2021-05-20 21:05:09 发布