DataInputStream and DataOutputStream in Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

DataInputStream and DataOutputStream in Java

Share This

Source code
package com.t4b.test; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.InputStream; public class DataInputStreamTest { public static void main(String[] args) { try { InputStream input = new FileInputStream("test.txt"); DataInputStream dinst = new DataInputStream(input); int count = input.available(); byte[] ary = new byte[count]; dinst.read(ary); for (byte bt : ary) { char k = (char) bt; System.out.print(k + "-"); } } catch (Exception e) { e.printStackTrace(); } } }


Source code
package com.t4b.test; import java.io.DataOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class DataOutputStreamTest { public static void main(String[] args) { try { FileOutputStream file = new FileOutputStream("test.txt"); DataOutputStream data = new DataOutputStream(file); data.writeInt(65); data.flush(); data.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.