Created
August 17, 2018 14:11
-
-
Save awwsmm/4c6b1d6b1000f06e6cc6e4566cef9c7d to your computer and use it in GitHub Desktop.
Read external file at Java runtime
This file contains 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
ENGLISH "yyyy-MM-dd HH:mm:ss" | |
ENGLISH "yyyy/MM/dd HH:mm:ss.SS" | |
ENGLISH "MM/dd/yyyy hh:mm:ss a" | |
ENGLISH "M/d/yy H:mm" | |
ENGLISH "dd/MM/yyyy HH:mm:ss" |
This file contains 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
import java.io.BufferedReader; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Entries { | |
public static void main (String[] args) { | |
final String fileName = "entries.dat"; | |
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)))) { | |
System.out.println("Reading data from a file at runtime:"); | |
String line = null; | |
while ((line = reader.readLine()) != null) | |
System.out.println(line); | |
} catch (FileNotFoundException ex) { | |
System.err.printf("External file '%s' not found!%n", fileName); | |
} catch (IOException ex) { | |
System.err.println("I/O Exception!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment