Skip to content

Instantly share code, notes, and snippets.

@awwsmm
Created August 17, 2018 14:11
Show Gist options
  • Save awwsmm/4c6b1d6b1000f06e6cc6e4566cef9c7d to your computer and use it in GitHub Desktop.
Save awwsmm/4c6b1d6b1000f06e6cc6e4566cef9c7d to your computer and use it in GitHub Desktop.
Read external file at Java runtime
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"
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