I’ve got a problem with reading an object from file..
in main, I made eshop end call a method loadshop.
MyShop eshop = new MyShop();
eshop.loadShop("eshop.txt");
and also I’m getting the shop object from file.
@Override
public void loadShop(String filename) {
try{
ObjectInput out = new ObjectInputStream(new FileInputStream(filename));
MyShop shop = (MyShop)out.readObject();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
But I just can’t figure out how to assign “shop” to “eshop”
Thank you for any answer..:-) (Sorry for my English)
Just redesign, you don’t need to write
Instead, write
and make the
loadShopmethod static. And make it return theMyShopinstance, if it isn’t already doing that.If this is not an option, it is still better to get that instance through a hack than to write manual copying code:
You’d use this like