I've noticed that whenever you use FileOutputStream
with append as true, the object that is appended is placed on a different line.
My question is how do you read multiple lines of data with ObjectInputStream
.
For ex:
public class StringBytes {
public static void main(String[] args) throws Exception {
String S1 = "Hi";
String S2 = "\n"+"Bye";
String file = "C:\\HiBye.out";
FileOutputStream fileOutputStream = new FileOutputStream(file);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(S1);
fileOutputStream = new FileOutputStream(file,true);
objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(S2);
FileInputStream fileInputStream = new FileInputStream(file);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
String SS = (String) objectInputStream.readObject();
System.out.println(SS);
}
}
The output for the above is Hi
since Bye
is on a different line it is not read.
I'm still a beginer so all help appreciated