I am having an error in my code why can't I get the 2nd array to read.
Layout:
public class Layout implements Serializable {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Layout(){
username="";
password="";
}
public Layout(String user,String pass){
username=user;
password=pass;
}
@Override
public String toString() {
return "Match Found! [Username: " + username + ", Password: " + password+"]";
}
}
Since I got my layout working I tried to serialized the user input and deserialized.
Serialize:
int i;
Layout[] items = new Layout[1];
CrunchifySerializeDeserialize c = new CrunchifySerializeDeserialize();
for (i = 0; i < items.length; i++) {
items[i] = c.new Layout();
}
String a = JOptionPane.showInputDialog("Enter Username");
String b = JOptionPane.showInputDialog("Enter Password");
items[0].setUsername(a);
items[0].setPassword(b);
System.out.println("Personal info Details.....");
for (Layout d : items) {
System.out.print(d.getUsername());
System.out.print("\t" + d.getPassword());
}
List<Layout> obj;
obj = new ArrayList<Layout>();
for (i = 0; i < items.length; i++) {
obj.add(items[i]);
}
items=new Layout[1];
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("./Test1.txt",true));
out.writeObject(obj);
out.close();
System.out.println("\nSerialization Successful... Checkout your specified output file..\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
In Deserialization I think that I got something wrong when reading right? And please correct me if am wrong xD *RIP ME.
try {
//FileInputStream fileIn = new FileInputStream("./Crunchify_Test1.txt");
ObjectInputStream in = new ObjectInputStream(new FileInputStream("./Test1.txt"));
boolean check = true;
while(check){
try{
System.out.println("Deserialized Data: \n" + in.readObject().toString());
//reinitailize shit
}catch(EOFException e){
check=false;
}
}
//System.out.println("Deserialized Data: \n" + in.readObject().toString());
in.close();
//fileIn.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Getting errors when adding in the txt file it shows "invalid type code: AC" it means that it cannot read another source in that *pile.