write read string data
Hi All,
I am attempting to write data into a file and read it
back again.
The error occurs with reading the data file back,
or so it would appear as the current output of that
data is merely a column of null.
Your help is appreciated.
bH
import java.io.*;
public class Example4withIO {
String[][] tmp_array = new String [5][5] ;
public static void main(String[] args) {
new Example4withIO();
}
public Example4withIO() {
// final String[] names = {"First Name",
// "Last Name", "Favorite Color",
// "Favorite Number", "Vegetarian"};
final Object[][] data = {
{"Mark", "Andrews", "Red", new Integer(2),
Boolean.TRUE},
{"Tom", "Ball", "Blue", new Integer(99),
Boolean.FALSE},
{"Alan", "Chung", "Green", new Integer(838),
Boolean.FALSE},
{"Jeff", "Dinkins", "Turquois", new Integer(8),
Boolean.TRUE},
{"Amy", "Fowler", "Yellow", new Integer(3),
Boolean.FALSE},
};
try {
FileOutputStream f_out = new FileOutputStream
("C:\\myarray.data");
ObjectOutputStream obj_out =
new ObjectOutputStream (f_out);
obj_out.writeObject(data);
obj_out.flush();
obj_out.close();
}
catch (IOException e)
{
System.out.println("error obj_out");
}
// end saving data
// attempting to recover the data
try {
BufferedReader obj_in =
new BufferedReader(new FileReader
("C:\\myarray.data"));
tmp_array.equals (obj_in);
obj_in.close();
}
catch (Exception eerr){
System.out.println("error getting in");
}
for(int ib=0;ib<5;ib++) {
for(int cb=0;cb<5;cb++) {
System.out.println(tmp_array[ib][cb]);
}
}//end recover of data
}
}