FileInPutStream类的使用

来源:互联网 发布:25n66aa数据 编辑:程序博客网 时间:2024/05/16 23:01
/* * 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 stubFile 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 blocke.printStackTrace();}finally {//关闭文件流try {fis.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}

阅读全文
0 0
原创粉丝点击