<<< Example: Sequential output of ASCII files | Index | >>> |
Class BufferedInputStream implements input stream of bytes
Class InputStreamReader
is a bridge from byte streams to character streams
reads bytes and decodes them into characters using a specified character set
for efficiency it is wrapped within BufferedReader.
// Reads employee data from ASCII text file sequentially, line by line import java.nio.file.*; import java.io.*; public class ReadEmployeeFile { public static void main(String[] args) { Path file = Paths.get("C:\\example\\Employees.txt"); String s = ""; try { InputStream input = new BufferedInputStream(Files.newInputStream(file)); // BufferedReader implements reading character files BufferedReader reader = new BufferedReader(new InputStreamReader(input)); // uses the default charset s = reader.readLine(); while(s != null) { System.out.println(s); s = reader.readLine(); } reader.close(); } catch(Exception e) { System.out.println("Message: " + e); } } }//class ReadEmployeeFile
<<< Example: Sequential output of ASCII files | Index | >>> |