import java.io.FileWriter; import java.io.IOException; public class Program01 { public static FileWriter openFile() { FileWriter fw = null; try { fw = new FileWriter("adat.txt", true); } catch(IOException ex) { System.err.println("Hiba a fájl megnyitása során!"); } return fw; } public static void writeFile(FileWriter fw) { try { tryWriteFile(fw); }catch(IOException ex) { System.err.println("Hiba a fájlba írás során!"); } } public static void tryWriteFile(FileWriter fw) throws IOException { fw.write("alma"); } public static void closeFile(FileWriter fw) { try { fw.close(); } catch(IOException ex) { System.err.println("Hiba fájl bezárása során!"); } } public static void main (String args[]) { FileWriter fw = openFile(); writeFile(fw); closeFile(fw); } }