The document provides 5 programming exercises involving reading and writing to text files. The exercises include calculating averages from a file of numbers, generating and writing random integers to a file, replacing strings in a text file, creating and saving objects to a data file, and reading from a data file and displaying employee information.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views
Exercises6 Java Text IO
The document provides 5 programming exercises involving reading and writing to text files. The exercises include calculating averages from a file of numbers, generating and writing random integers to a file, replacing strings in a text file, creating and saving objects to a data file, and reading from a data file and displaying employee information.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Ex 1. Shows that the text file data.
txt contains a sequence of real
numbers with undefined numbers, each separated by spaces. Write the above program and print the total average value of the string in the file.
Example:
Read numbers separated by enters or spaces
Java read file line by line
Ex 2. Write a program that creates a text file called IntData.txt if the file does not already exist. Generates and writes 100 random integers to the file above, each separated by spaces. Read the file and print the dimensioned sequence.
Ex 3. The ReplaceText.java program reads the text from
sourceFile, changes the oldString string to newString strings, and saves the new text and destFile. Please install the program on.
Ex 4. Write a program that creates 10 objects (Class attributes:
employee code, full name, year of birth, product number) and saves them to the employeelist.dat file.
Ex 5. Write the dsnhanvien.dat file reader in exercise 4 and
display the information screen: Employee has the largest product. Total number of employees in the file.