さて、私は簡単なクラスを書いていたので、try-catch-finally (それをするのは嫌い) メソッドの代わりにリソースを使用して try を使用しようとしましたが、「不正な型の開始」というエラーが発生し続けます。次に、Java チュートリアルのセクションに目を向けるとhttp://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
、括弧内に新しい変数を割り当てることができることが示されました。何が起こっているのかわかりません。
private static final class EncryptedWriter {
private final Path filePath;
private FileOutputStream outputStream;
private FileInputStream inputStream;
public EncryptedWriter(Path filePath) {
if (filePath == null) {
this.filePath = Paths.get(EncryptionDriver.RESOURCE_FOLDER.toString(), "Encrypted.dat");
} else {
this.filePath = filePath;
}
}
public void write(byte[] data) {
try (this.outputStream = new FileOutputStream(this.filePath.toFile())){
} catch (FileNotFoundException ex) {
Logger.getLogger(EncryptionDriver.class.getName()).log(Level.SEVERE, null, ex);
}
}
}