Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java FileOutputStream to write data to a File

import java.io.FileOutputStream;
public class Main {
    public static void main(String[] args) {
       String data = "This is a line of text inside the file.";
        try {
            FileOutputStream output = new FileOutputStream("output.txt");

            byte[] array = data.getBytes();

            // Writes byte to the file
            output.write(array);

            output.close();
        }
        catch(Exception e) {
            e.getStackTrace();
        }
    }
}
 
PREVIOUS NEXT
Tagged: #Java #FileOutputStream #write #data #File
ADD COMMENT
Topic
Name
5+9 =