-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53681de
commit 5248fef
Showing
8 changed files
with
17,531 additions
and
2 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
core-banking/src/com/example/banking/application/ReadCustomerFromFile.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.banking.application; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
|
||
import com.example.banking.domain.Account; | ||
import com.example.banking.domain.CheckingAccount; | ||
import com.example.banking.domain.Customer; | ||
|
||
public class ReadCustomerFromFile { | ||
|
||
public static void main(String[] args) throws Exception { | ||
var file = new File("c:/tmp", "jack.dat"); | ||
// try-with-resources, Java 7+ | ||
try (var fis = new FileInputStream(file); | ||
var ois = new ObjectInputStream(fis);) { | ||
Customer jack = (Customer) ois.readObject(); | ||
System.err.println(jack); | ||
var totalBalance = jack.getTotalBalance(); | ||
System.err.println("Total balance: "+totalBalance); | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
core-banking/src/com/example/banking/application/WriteCustomerToFile.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.banking.application; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.ObjectOutputStream; | ||
|
||
import com.example.banking.domain.Account; | ||
import com.example.banking.domain.CheckingAccount; | ||
import com.example.banking.domain.Customer; | ||
|
||
public class WriteCustomerToFile { | ||
|
||
public static void main(String[] args) throws Exception { | ||
var jack = new Customer("1111111110", "Jack Bauer"); | ||
jack.addAccount(new Account("tr1", 100_000)); | ||
jack.addAccount(new CheckingAccount("tr2", 200_000, 5_000)); | ||
jack.addAccount(new Account("tr3", 300_000)); | ||
var file = new File("c:/tmp", "jack.dat"); | ||
// try-with-resources, Java 7+ | ||
try (var fos = new FileOutputStream(file); | ||
var oos = new ObjectOutputStream(fos);) { | ||
oos.writeObject(jack); | ||
} | ||
System.err.println("Object is written to the 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
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
Oops, something went wrong.