DataOutputStream In Java Example

Chapter: Java I/O Last Updated: 21-07-2016 18:08:59 UTC

Program:

            /* ............... START ............... */
                
import java.io.DataOutputStream;
import java.io.FileOutputStream;

public class JavaDataOutputStream {
	public static void main(String[] args) {

		try {

			String content = "Data Input Stream Examnple.\n";
			byte[] array = content.getBytes();

			FileOutputStream fos = new FileOutputStream("file.txt");
			DataOutputStream dos = new DataOutputStream(fos);

			for (byte b : array) {
				dos.write(b);
			}
			dos.close();
			fos.close();

		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}

	}
}
                /* ............... END ............... */
        

Notes:

  • The Java.io.DataOutputStream class lets an application write primitive Java data types to an output stream in a portable way.

Tags

DataOutputStream , Java, Java I/O

Similar Programs Chapter Last Updated
Hidden File Check In Java Example Java I/O 20-06-2016
FileWriter In Java Example Java I/O 21-07-2016
FileReader In Java Example Java I/O 21-07-2016
FileOutputStream In Java Example Java I/O 21-07-2016
FileInputStream In Java Example Java I/O 21-07-2016
DataInputStream In Java Example Java I/O 21-07-2016
CharArrayWriter In Java Example Java I/O 13-04-2016
CharArrayReader In Java Example Java I/O 21-07-2016
ByteArrayOutputStream In Java Example Java I/O 21-07-2016
ByteArrayInputStream In Java Example Java I/O 21-07-2016
BufferedWriter In Java Example Java I/O 21-07-2016
BufferedReader In Java Example Java I/O 21-07-2016
BufferedOutputStream In Java Example Java I/O 21-07-2016
BufferedInputStream In Java Example Java I/O 21-07-2016
ProcessBuilder To Make System Calls In Java Java I/O 19-08-2017

1