How to read file in Java – BufferedInputStream Example
2010-07-02 17:53
477 查看
import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class UseBufferedInputStream { public static void main(String[] args) { File file = new File("C://readFile.txt"); FileInputStream fis = null; BufferedInputStream bis = null; DataInputStream dis = null; try { fis = new FileInputStream(file); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); while (dis.available() != 0) { System.out.println(dis.readLine()); } fis.close(); bis.close(); dis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- How to Parse or Read XML File in Java >> XML Tutorial Example
- How to Read, Write XLSX File in Java - Apach POI Example---reference
- Step By Step guide to Read XML file in Java Using SAX Parser Example
- How to decompile class file in Java and Eclipse - Javap command example(转)
- How To Read XML File In Java – (SAX Parser)
- In Java, how do I read/convert an InputStream to a String? - Stack Overflow
- How to read and parse CSV file in Java
- How To Read XML File In Java – (DOM Parser)
- PDFBox – How to read PDF file in Java
- How to Create and Evaluate XPath Expression in Java - Tutorial and Example
- Shell: How to read lines in a file.
- How to upload a file via a HTTP multipart request in Java without using any external libraries
- How to read data from a file in reverse order?
- Java实现读取pdf文件内容(how to read pdf in java)
- How to Iterate over Array in Java 1.5 using foreach loop Example
- Why is using BufferedInputStream to read a file byte by byte faster than using FileInputStream
- How to read ini file using Java
- How to read and write JSON files in Java(Gson)
- How to read Mac .DMG file in Linux or PC(II)
- How To Create XML File In Java – (DOM Parser)