Created
September 5, 2016 03:16
-
-
Save grim13b/32cb3da7be742084b0a8802265eebc65 to your computer and use it in GitHub Desktop.
よくわからん例
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
package org.grim3lt.example.Hogehoge; | |
import lombok.Cleanup; | |
import java.io.*; | |
import java.util.Arrays; | |
public class Hogehoge { | |
public static void main(String[] args) { | |
Hogehoge hogehoge = new Hogehoge(); | |
hogehoge.hoge1("/tekitouna/path/hoge.txt"); | |
hogehoge.hoge2("/tekitouna/path/hoge.txt"); | |
} | |
private void hoge1(String filename) { | |
try { | |
@Cleanup InputStream in = new FileInputStream(filename); | |
byte[] hoge = new byte[1024]; | |
while(in.read(hoge) != -1) { | |
System.out.println("hoge1" + Arrays.toString(hoge)); | |
// このあたりで例外投げても | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
private void hoge2(String filename) { | |
try (InputStream in = new FileInputStream(filename)) { | |
byte[] hoge = new byte[1024]; | |
while(in.read(hoge) != -1) { | |
System.out.println("hoge2" + Arrays.toString(hoge)); | |
// このあたりで例外投げても | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
// Nest的には変わらないし in のスコープが Cleanup だと | |
// 見づらいしというだけの理由 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment