-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab11Prob01.java
More file actions
39 lines (38 loc) · 1.16 KB
/
Copy pathLab11Prob01.java
File metadata and controls
39 lines (38 loc) · 1.16 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
/**
* File: Lab11Prob01.java
* Class: CSCI 1302
* Authors: Eli McHugh, Rendy Jenkins
* Last Modified: November 22, 2024
* Description: Read people.dat and print to a copy file as well as the console
*/
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileOutputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
public class Lab11Prob01 {
public static void main(String args[]) {
try (
DataInputStream input = new DataInputStream(new FileInputStream("src/people.dat"));
DataOutputStream output = new DataOutputStream(new FileOutputStream("src/people-copy.dat"));
) {
while(true) {
int age = input.readInt();
output.writeInt(age);
String name = input.readUTF();
output.writeUTF(name);
String Address = input.readUTF();
output.writeUTF(Address);
int zipCode = input.readInt();
output.writeInt(zipCode);
double salary = input.readDouble();
output.writeDouble(salary);
System.out.printf("%d %s %s %d %.2f%n", age, name, Address, zipCode, salary);
}
} catch (EOFException e) {
System.out.print("");
} catch (Exception e) {
e.printStackTrace();
}
}
}