-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlefile.java
More file actions
56 lines (43 loc) · 1.94 KB
/
Handlefile.java
File metadata and controls
56 lines (43 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Handlefile {
private static UserProfiles savedProfiles = null;
private static Path currentRelativePath = Paths.get("");
private static String workingDir = currentRelativePath.toAbsolutePath().toString();
public static void writeUserProfiles(UserProfiles profile) throws IOException{
FileOutputStream userProfileFile = new FileOutputStream("UserProfile.ser");
ObjectOutputStream userProfileOut = new ObjectOutputStream(userProfileFile);
userProfileOut.writeObject(profile);
userProfileOut.close();
userProfileFile.close();
}
public static UserProfiles readUserProfiles() throws ClassNotFoundException, IOException{
FileInputStream FileIn = new FileInputStream(workingDir + "/UserProfile.ser");
ObjectInputStream in = new ObjectInputStream(FileIn);
savedProfiles = (UserProfiles) in.readObject();
in.close();
FileIn.close();
return savedProfiles;
}
public static User readUserFile(String filename) throws ClassNotFoundException, IOException{
FileInputStream FileIn11 = new FileInputStream(workingDir + "/"+filename+".ser");
ObjectInputStream in11 = new ObjectInputStream(FileIn11);
User user = (User) in11.readObject();
in11.close();
FileIn11.close();
return user;
}
public static void writeUserFile(User user) throws IOException{
FileOutputStream userProfileFileatt = new FileOutputStream(user.getUserName()+".ser");
ObjectOutputStream userProfileOutatt = new ObjectOutputStream(userProfileFileatt);
userProfileOutatt.writeObject(user);
userProfileOutatt.close();
userProfileFileatt.close();
return;
}
}