Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Created June 11, 2017 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksakae1216/6c842c7838e9282eaeb264932721925f to your computer and use it in GitHub Desktop.
Save ksakae1216/6c842c7838e9282eaeb264932721925f to your computer and use it in GitHub Desktop.
// try-with-resourcesでファイル読み込み
private void newFileRead(String file) {
try(FileInputStream fi = new FileInputStream(file);
InputStreamReader in = new InputStreamReader(fi);
BufferedReader br = new BufferedReader(in)) {
// ファイル読み込み
String line;
while( (line = br.readLine()) != null) {
System.out.println(line);
}
} catch(Exception e) {
} finally {
// クローズ処理不要
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment