Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.io.FileOutputStream; public class JavaFileOutputStream { public static void main(String[] args) { String content = "Welcome To code4example.com"; byte[] bytes = content.getBytes(); try { FileOutputStream fos = new FileOutputStream("JavafileExample.txt"); fos.write(bytes); fos.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } |
The Java.io.FileOutputStream class is an output stream for writing data to a File or to a FileDescriptor.
FileOutputStream(File file) – creates a file output stream to write to the file represented by the specified File object.