InputStream 一个字节一个字节的读取
2016-06-05 12:08
169 查看
package chap10.sec03;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class Demo4 {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File file =new File("D:/测试文件.txt");
InputStream in=new FileInputStream(file);//实例化FileInputStream
int fileLength=(int)file.length();
byte b[]=new byte[fileLength];
int temp=0;
int len=0;
while((temp=in.read())!=-1){
b[len++]=(byte) temp;
}
in.close();
System.out.println("读取到的内容是:"+new String(b));
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class Demo4 {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File file =new File("D:/测试文件.txt");
InputStream in=new FileInputStream(file);//实例化FileInputStream
int fileLength=(int)file.length();
byte b[]=new byte[fileLength];
int temp=0;
int len=0;
while((temp=in.read())!=-1){
b[len++]=(byte) temp;
}
in.close();
System.out.println("读取到的内容是:"+new String(b));
}
}
相关文章推荐
- 河南省第九届ACM赛后总结
- 经验累积
- TCP,UDP,三次握手
- 域名与DNS(域名解析服务器)
- eclipse配置maven和svn插件
- android4.4的短信发送流程
- C++作业7-函数复习
- 第十五周项目—阅读程序(3)
- httpd之日志切割
- 【转】CSS3的自定义字体@font-face:如何将icon变成字体?
- 理解Java对象序列化
- __stdcall、__cdcel和__fastcall三者的区别
- poj2993Emag eht htiw Em Pleh
- 用python自动发推(twitter)
- 字符编码笔记:ASCII,Unicode和UTF-8
- Hibernate表间级联
- Visual Studio 2013安装
- Collection集合介绍
- poj2996Help Me with the Game
- java同时启动多个线程