您的位置:首页 > 其它

字节符输入流 InputStreamDemo

2015-11-21 11:27 239 查看
import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStream;

public class InputStreamDemo 

{

public static void main(String[] args) 

{

File file = new File("d:\\a\\a.txt");     //要读取的文件路径;

if(!file.exists())

{

System.out.println("文件不存在");

System.exit(-1); //文件不存在,退出;

}

InputStream is = null; //字节输出流;

try 

{

is = new FileInputStream(file);

byte[] b = new byte[(int)file.length()];//根据文件大小;

is.read(b);//读取;

System.out.println(new String(b));//在控制台输出;

is.close();//关闭流;

} catch (FileNotFoundException e)

 {

e.printStackTrace();

}catch(IOException e)

{

e.printStackTrace();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: