As the purpose of writeByte() is same in both classes. But both are writing different contents.
import java.io.*;
class First
{
public static void main(String[] args) throws IOException
{
FileOutputStream fos = new FileOutputStream("b.txt");
Line 1: ObjectOutputStream oos = new ObjectOutputStream(fos);
Line 2: DataOutputStream oos = new DataOutputStream(fos);
oos.writeByte(65);
oos.close();
FileInputStream fis = new FileInputStream("b.txt");
int x=0;
System.out.println("Output");
while((x=fis.read())!=-1)
{
System.out.println(x);
}
fis.close();
}
}
If Line 1 is commented out, output is:
65
If Line 2 is commented out, output is:
172
237
0
5
119
1
65
Why this difference?