使用BufferedInputStream读取文件内容,,package cn.o
分享于 点击 17977 次 点评:274
使用BufferedInputStream读取文件内容,,package cn.o
package cn.outofmemory.snippets.core;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;public class ReadFileWithBufferedInputStream { public static void main(String[] args) { File file = new File("inputfile.txt"); BufferedInputStream bin = null; FileInputStream fin = null; try { // create FileInputStream object fin = new FileInputStream(file); // create object of BufferedInputStream bin = new BufferedInputStream(fin); // read file using BufferedInputStream while (bin.available() > 0) { System.out.print((char) bin.read()); } } catch (FileNotFoundException e) { System.out.println("File not found" + e); } catch (IOException ioe) { System.out.println("Exception while reading file " + ioe); } finally { // close the streams using close method try { if (fin != null) { fin.close(); } if (bin != null) { bin.close(); } } catch (IOException ioe) { System.out.println("Error while closing stream : " + ioe); } } }}
用户点评