The document shows Java code that writes a line of text and numeric data to an output file. It imports FileOutputStream and OutputStream classes, declares a string variable containing sample text and numeric data, creates a FileOutputStream object to write to an output file, converts the string to bytes, writes the bytes to the output stream, prints a message that data was written, and closes the output stream, catching any exceptions.
The document shows Java code that writes a line of text and numeric data to an output file. It imports FileOutputStream and OutputStream classes, declares a string variable containing sample text and numeric data, creates a FileOutputStream object to write to an output file, converts the string to bytes, writes the bytes to the output stream, prints a message that data was written, and closes the output stream, catching any exceptions.
The document shows Java code that writes a line of text and numeric data to an output file. It imports FileOutputStream and OutputStream classes, declares a string variable containing sample text and numeric data, creates a FileOutputStream object to write to an output file, converts the string to bytes, writes the bytes to the output stream, prints a message that data was written, and closes the output stream, catching any exceptions.
public static void main(String args[]) { String data = "This is a line of text inside the file. 123 sample"; try { OutputStream out = new FileOutputStream("output.txt"); // Converts the string into bytes byte[] dataBytes = data.getBytes(); // Writes data to the output stream out.write(dataBytes); System.out.println("Data is written to the file."); // Closes the output stream out.close(); } catch (Exception e) { e.getStackTrace(); } } }