java读取文件

File file = new File("D:\test\文件发送测试.txt");
if(!file.exists()){
System.out.println("文件不存在");

}else{
FileInputStream fin = new FileInputStream(file);
//创建一个长度为1024的竹筒
byte[] bbuf = new byte[1024];
//用于保存实际读取的字节数
int hasRead = 0;
//使用循环来重复“取水”的过程
while((hasRead = fin.read(bbuf))>0)
{
//取出"竹筒"中(字节),将字节数组转成字符串输入
System.out.println(new String(bbuf,0,hasRead));
}
fin.close();

}

原文地址:https://www.cnblogs.com/lijiahong/p/5362194.html