FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Swing-Registration-Quiz-App/UserDatabase.java at main · gaureshpai/Java-Swing-Registration-Quiz-App · GitHub
This repository was archived by the owner on Jul 3, 2025. It is now read-only.
gaureshpai
/
Java-Swing-Registration-Quiz-App
Public archive
Notifications
You must be signed in to change notification settings
Fork
5
Star
23
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Swing-Registration-Quiz-App
/
UserDatabase.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (38 loc) · 1.62 KB
Breadcrumbs
Java-Swing-Registration-Quiz-App
/
UserDatabase.java
Copy path
File metadata and controls
41 lines (38 loc) · 1.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
io
.*;
import
java
.
util
.*;
public
class
UserDatabase
{
private
static
final
String
FILENAME
=
"users.txt"
;
public
static
User
[]
loadUsers
() {
List
<
User
>
userList
=
new
ArrayList
<>();
try
(
BufferedReader
br
=
new
BufferedReader
(
new
FileReader
(
FILENAME
))) {
String
line
;
while
((
line
=
br
.
readLine
()) !=
null
) {
String
[]
parts
=
line
.
split
(
","
);
if
(
parts
.
length
==
4
) {
String
username
=
parts
[
0
];
char
[]
password
=
parts
[
1
].
toCharArray
();
String
securityQuestion
=
parts
[
2
];
String
securityAnswer
=
parts
[
3
];
userList
.
add
(
new
User
(
username
,
password
,
securityQuestion
,
securityAnswer
));
}
}
}
catch
(
FileNotFoundException
e
) {
System
.
err
.
println
(
"Error: users.txt file not found."
);
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
System
.
err
.
println
(
"Error loading users: "
+
e
.
getMessage
());
}
return
userList
.
toArray
(
new
User
[
0
]);
}
public
static
void
saveUsers
(
User
[]
users
) {
try
(
PrintWriter
writer
=
new
PrintWriter
(
new
FileWriter
(
FILENAME
))) {
for
(
User
user
:
users
) {
writer
.
println
(
user
.
getUsername
() +
","
+
String
.
valueOf
(
user
.
getPassword
()) +
","
+
user
.
getSecurityQuestion
() +
","
+
user
.
getSecurityAnswer
());
}
writer
.
flush
();
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
System
.
err
.
println
(
"Error saving users: "
+
e
.
getMessage
());
}
}
}
Back
|
FazBrowse Home
|
New Git URL