import
java.io.*;
class
ObjectOutputStreamDemo
{
public
static
void
main(String[] args)
throws
IOException, ClassNotFoundException
{
FileOutputStream fout =
new
FileOutputStream(
"file.txt"
);
ObjectOutputStream oot =
new
ObjectOutputStream(fout);
String a =
"GeeksforGeeks"
;
String b =
"Geek"
;
byte
[] be = {
'A'
,
'B'
,
'C'
};
oot.write(
1
);
oot.writeInt(
1
);
oot.writeBoolean(
true
);
oot.writeObject(a);
oot.writeByte(
65
);
oot.writeBytes(b);
oot.writeDouble(
2.3
);
oot.writeUTF(a);
oot.writeFloat(
2
.42f);
oot.writeLong(234342347908l);
oot.writeChars(a);
oot.writeShort(
2
);
oot.write(be);
oot.flush();
oot.close();
byte
c[]=
new
byte
[
4
];
char
c1[]=
new
char
[
13
];
FileInputStream fin =
new
FileInputStream(
"file.txt"
);
ObjectInputStream oit =
new
ObjectInputStream(fin);
System.out.println(oit.read());
System.out.println(oit.readInt());
System.out.println(oit.readBoolean());
System.out.println(oit.readObject());
System.out.println(oit.readByte());
oit.read(c);
for
(
int
i =
0
; i <
4
; i++)
{
System.out.print((
char
)c[i]);
}
System.out.println();
System.out.println(oit.readDouble());
System.out.println(oit.readUTF());
System.out.println(oit.readFloat());
System.out.println(oit.readLong());
for
(
int
i =
0
; i <
13
; i++)
{
System.out.print(oit.readChar());
}
System.out.println();
System.out.println(oit.readShort());
oit.readFully(be);
for
(
int
i =
0
; i <
3
; i++)
{
System.out.print((
char
)be[i]);
}
oit.close();
}
}