import java.io.IOException; public class res3 implements ires { public void write(String filename, String msg) throws Exception { try ( FileOutputStream out = new FileOutputStream(filename); // may throw FileNotFoundException FileOutputStream log = new FileOutputStream("log.txt"); // or SecurityException ) { out.write(msg.getBytes()); // may throw an IOException log.write(msg.getBytes()); // may throw an IOException } } public static void main(String[] args) { res.dotest(new res3()); } }