Question: 1. Create a FileCopier class to copy file with byte streams . Create a new file called groceries.txt. Enter a grocery list in TXT file
1. Create a FileCopier class to copy file with byte streams. Create a new file called groceries.txt. Enter a grocery list in TXT file and save it (one item per line). Copy the grocery list in TXT to a new TXT file named groceries (copy).txt.
apples
bananas
water
orange juice
milk
bread
FileInputStream / FileOutputStream
Declare a String variable and initialize it to today is a good day . Write it to groceries (copy).txt.
Modify the code to append output to file with FileOutputStream.
2. Write a program that save the sale detail as below table in the invoice.dat with data streams. Then read the sale details out from the file and generate the sale report as show below.
DataInputStream / DataOutputStream
| Item | Price | Quantity |
| SoCIT T-Shirt | 25.00 | 10 |
| SoCIT Mug | 10.00 | 15 |
| SoCIT Doll | 8.00 | 20 |
| SoCIT Pin | 2.50 | 20 |
| SoCIT Key Chain | 3.00 | 30 |
Output in console:
You ordered 10 units of SoCIT T-Shirt at RM25.00
You ordered 15 units of SoCIT Mug at RM10.00
You ordered 20 units of SoCIT Doll at RM8.00
You ordered 20 units of SoCIT Pin at RM2.50
You ordered 30 units of SoCIT Chain at RM3.00
Amount Paid RM 700.00
3. Revise the program in Question 3, where sale details are formatted in columns where each column is separated from the next by tabs. The columns contain the sales price, the number of units ordered, and a description of the item should be saved in invoice1.dat. Then read the sale details out from the file and generate the sale report.
25.00 10 SoCIT T-Shirt
10.00 15 SoCIT Mug
8.00 20 SoCIT Doll
2.50 20 SoCIT Pin
3.00 30 SoCIT Key Chain
4. Write a program that determine number of bytes written to DataOutputStream.
5. Revise the Question 1, copy the FileCopier class and refactor (paste) it as a new class file namely FileCopierBuffer. The FileCopierBuffer will copy the grocery list using buffered character streams.
BufferedReader == out
BufferedWriter == in
apples
bananas
water
orange juice
milk
bread
6. (Encrypt files) Encode the file by adding 5 to every byte in the file. Write a program that prompts the user to enter an input file name and an output file name and saves the encrypted version of the input file to the output file.
7. (Decrypt files) Suppose a file is encrypted using the scheme in Question 5. Write a program to decode an encrypted file. Your program should prompt the user to enter an input file name for the encrypted file and an output file name for the unencrypted version of the input file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
