import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class App { public static void writeFile() { try { tryWriteFile(); } catch (IOException e) { System.err.println("Hiba! A fájl nem olvasható!"); } } public static void tryWriteFile() throws IOException { Path path = Paths.get("adat.txt"); Charset cs = StandardCharsets.UTF_8; BufferedWriter writer = Files.newBufferedWriter(path, cs); writer.write("Valami"); writer.close(); } public static void main(String[] args) throws Exception { writeFile(); } }