Created
May 2, 2014 06:04
-
-
Save justgage/8510a8d1fcc3a68d67e0 to your computer and use it in GitHub Desktop.
A simple example of writing a java object to a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
class wallet implements java.io.Serializable { | |
private double balence; | |
public double check() { | |
return balence; | |
} | |
public double add(double num) { | |
return balence += num; | |
} | |
public static void main(String[] args) { | |
if (args.length > 0) { | |
String filename = args[0]; | |
wallet mywallet = new wallet(); | |
FileOutputStream fos = null; | |
ObjectOutputStream out = null; | |
try { | |
fos = new FileOutputStream(filename); | |
out = new ObjectOutputStream(fos); | |
out.writeObject(mywallet); | |
out.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} else { | |
System.out.println("Please enter wallet name."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment