"Example 1"
Import Java.io.DataOutputStream; Import Java.io.File; Import Java.io.FileOutputStream; Import java.io.IOException;PublicClass dataoutputstreamdemo{public static void main (string[] args) throws ioexception{file File = new file ("D:" + File.separa Tor + "Hello.txt"); char[] ch = { "A", "B", "C"}; DataOutputStream out = null; out = new DataOutputStream (new FileOutputStream (file)); For (char temp:ch) { Out.writechar (temp);} out.close ();}}
"Run Results":
A B C
Now let's use DataInputStream to read the content, based on the example above.
"Example 2"
Import Java.io.DataInputStream;Import Java.io.File;Import Java.io.FileInputStream;Import java.io.IOException;PublicClassdataoutputstreamdemo{public static void main (string[] args) throws ioexception{File File = new file ("D:" + file.se Parator + "Hello.txt"); DataInputStream input = new DataInputStream (new FileInputStream (file)); char[] ch = new char[10]; int count = 0; Char temp; while ((temp = Input.readchar ()) = "C") {ch[count++] = temp;} SYSTEM.OUT.PRINTLN (CH); }}
"Run Results":
AB
Data manipulation flow DataOutputStream, DataInputStream class