Last active
August 29, 2015 14:05
-
-
Save diegogaulke/499ad54fcaa679b6df9f to your computer and use it in GitHub Desktop.
Read data from a text file with Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dg2ee.io; | |
import java.io.BufferedInputStream; | |
import java.io.DataInputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
public class BufferedInputStreamExample { | |
public static void main(String[] args) { | |
File file = new File("C:\\test.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()); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
fis.close(); | |
bis.close(); | |
dis.close(); | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment