try-with-resourcesとは?
try-with-resources 文 (oracle.com)より抜粋
try-with-resources 文は、1 つ以上のリソースを宣言するtry文です。リソースは、プログラムでの使用が終わったら閉じられなければいけないオブジェクトです。try-with-resources 文は、文の終わりで各リソースが確実に閉じられるようにします。java.io.Closeableを実装しているすべてのオブジェクトも含め、java.lang.AutoCloseableインタフェースを実装しているオブジェクトはリソースとして使用できます。
つまり何が言いたいかというとtryブロックが終了した時にリソースを解放(close)してくれる。
try-finallyでの書き方
public static String fileOutput(byte byteDate) {
  FileOutputStream out = null;
  try {
    out = new FileOutputStream(hogehoge.txt);
    out.write(byteDate);
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    if (out != null){
      try {
        out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}closeメソッド呼出でIOExceptionの可能性があるため、さらにtry-catch文を追加する必要がある
try-with-resourcesでの書き方
public static String fileOutput(byte byteDate) {
  try(FileOutputStream out = new FileOutputStream(hogehoge.txt)) {
    out.write(byteDate);
  } catch (IOException e) {
    e.printStackTrace();
  }
}すっきりするね

