Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.io.FileWriter; public class Main { public static void main(String[] args) { try { String content = "Welcome To Code4Example.\n"; FileWriter fileWriter = new FileWriter("Javafile.txt"); fileWriter.write(content); fileWriter.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } |
FileWriter is the simplest way to write a file in java, it provides overloaded write method to write int, byte array and String to the File.