Question: Consider the code snippet below. You have to write a program that records the names and scores of students into a file and reads from
Consider the code snippet below. You have to write a program that records the names and scores of students into a file and reads from the same file to display the names and scores. The file is named studentscores.txt Marks For example: If the data entered is: John: Alice: Bob: Then the output should be: Writing to file successful.Writing to file successful.Writing to file successful.Reading from file:John: Alice: Bob: To assist with the task, two methods writeToFile and readFromFile are given in the program.You have to fill the missing code in each of the methods, so that we get the above output. Java code:import java.io; public class StudentScores File name constant private static final String FILENAME "studentscores.txt; Writes a student's name and score to the file public static void writeToFileString name, int score try BufferedWriter bw new BufferedWriternew FileWriterFILENAME, trueMISSING CODE A System.out.printlnWriting to file successful."; catch IOException e eprintStackTrace; Reads and displays the content of the file public static void readFromFile System.out.printlnReading from file:"; try BufferedReader br new BufferedReadernew FileReaderFILENAMEMISSING CODE B catch IOException e eprintStackTrace; The main method for testing the file read and write operations public static void mainString args writeToFileJohn; writeToFileAlice; writeToFileBob; MISSING CODE C
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
