DataInput and DataOutput Example

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class DataInputOutputDemo1 {
    void write() {
        try {
            DataOutputStream dout = new DataOutputStream(new FileOutputStream("data2.txt"));
            dout.writeInt(100);
            dout.writeInt(200);
            dout.close();
        } catch (Exception e) {
        }
    }
    void read() {
        int i = 0;
        try {
            DataInputStream din = new DataInputStream(new FileInputStream("data2.txt"));
            while ((i = din.readInt()) != -1) {
                System.out.println(i);
            }
            din.close();
        } catch (Exception e) {
        }
    }
    public static void main(String[] args) {
        String currentdir = System.getProperty("user.dir");
        System.out.println(currentdir);
        new DataInputOutputDemo1().write();
		new DataInputOutputDemo1().read();
		}
}

Download

Input and Output Stream in Java

Example FileOutputStream
Example FileInputStream
DataInput and Output Example
Object Serialization
Object Deserialization
Object Externalizable Example
Example java.io.File class
RandomAccessFile Example


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code