public void loadInventroy(String world) { try { File f = new File(world, "store.dat"); DataInputStream input = new DataInputStream(new FileInputStream(f)); SKTagCompound comp = new SKTagCompound(); comp.readTagContents(input); credits = comp.getInteger("credits"); readFromNBT(comp); input.close(); } catch (FileNotFoundException e) { System.out.println("No store exists for " + world); credits = 0; } catch (IOException e) { e.printStackTrace(); } previousValue = calcValue(); }
public void saveInventory(String world) { try { File f = new File(world, "store.dat"); f.createNewFile(); DataOutputStream out = new DataOutputStream(new FileOutputStream(f)); SKTagCompound comp = new SKTagCompound(); comp.setInteger("credits", credits); writeToNBT(comp); comp.writeTagContents(out); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }