File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed
src/main/java/com/examplehub Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change 55public class SerializableExample {
66 public static void main (String [] args ) throws IOException , ClassNotFoundException {
77 User user = new User (1 , "root" , "root" );
8- try (ObjectOutputStream stream = new ObjectOutputStream (new FileOutputStream ("user.data" ))) {
8+ FileOutputStream fos = null ;
9+ ObjectOutputStream stream = null ;
10+ try {
11+ fos = new FileOutputStream ("user.data" );
12+ stream = new ObjectOutputStream (fos );
913 stream .writeObject (user );
14+ } finally {
15+ if (stream != null ) {
16+ stream .close ();
17+ }
18+ if (fos != null ) {
19+ fos .close ();
20+ }
1021 }
1122
12- try (ObjectInputStream inputStream = new ObjectInputStream (new FileInputStream ("user.data" ))) {
13- User newUser = (User ) inputStream .readObject ();
23+ ObjectInputStream ois = null ;
24+ FileInputStream fis = null ;
25+ try {
26+ fis = new FileInputStream ("user.data" );
27+ ois = new ObjectInputStream (fis );
28+ User newUser = (User ) ois .readObject ();
1429 System .out .println (newUser ); /* User{id=1, username='root', password='root'} */
30+ } finally {
31+ if (fis != null ) {
32+ stream .close ();
33+ }
34+ if (ois != null ) {
35+ ois .close ();
36+ }
1537 }
1638 }
1739}
Original file line number Diff line number Diff line change @@ -16,10 +16,6 @@ public static long solution1() {
1616 if (CharToInt .toInt (chars [j + 1 ]) - CharToInt .toInt (chars [j ]) != 1 ) {
1717 break ;
1818 }
19- if (j == chars .length - 1 ) {
20- System .out .println (i );
21- return i ;
22- }
2319 }
2420 }
2521 return 0 ;
You can’t perform that action at this time.
0 commit comments