-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateBinaryStudents.java
More file actions
39 lines (31 loc) · 1.07 KB
/
CreateBinaryStudents.java
File metadata and controls
39 lines (31 loc) · 1.07 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
/**
* ITEC 3150 - 01 Spring 2026
* IC 1
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CreateBinaryStudents {
public static void main(String[] args) {
try (DataOutputStream out = new DataOutputStream(new FileOutputStream("Students.dat"))) {
// Record format (repeat):
// int id, UTF name, double gpa
out.writeInt(1001);
out.writeUTF("Ava Kim");
out.writeDouble(3.82);
out.writeInt(1002);
out.writeUTF("Noah Patel");
out.writeDouble(3.45);
out.writeInt(1003);
out.writeUTF("Mia Johnson");
out.writeDouble(3.95);
out.writeInt(1004);
out.writeUTF("Ethan Garcia");
out.writeDouble(2.90);
System.out.println("Students.dat created successfully.");
} catch (IOException e) {
System.out.println("Error creating Students.dat");
e.printStackTrace();
}
}
}