Java Programming Assignment
Writing Student Records to a Text File
Objective
In this assignment, you will practice file output in Java by writing structured student data to a
text file. You will use file-handling classes to store formatted student records in an external .txt
file.
This assignment reinforces:
● List<String> usage
● The [Link]() method
● File writing using PrintWriter or FileWriter
● Exception handling (try-catch or throws IOException)
● Proper program structure and formatting
Provided Data
Your program must use the following data exactly as written:
Java
List<String> students = [Link](
"Alice Smith, 1001, Intro to Java, A",
"Bob Johnson, 1002, Data Structures, B+",
"Charlie Brown, 1003, Algorithms, C",
"Diana Prince, 1004, Operating Systems, A-"
);
Program Requirements
1️⃣ Create a Class
Create a class named:
None
StudentFileWriter
2️⃣ Write Data to a File
Your program must:
● Create a file named:
None
student_records.txt
●
Write all student records into the file
● Each student record must appear on its own line
● Preserve formatting exactly as shown
3️⃣ Use Proper File Handling
You must:
● Use either:
○ PrintWriter
○ FileWriter
○ OR a combination of both
● Properly close the file
● Handle possible exceptions using:
○ try-catch
○ OR throws IOException
4️⃣ Console Output
After successfully writing to the file, display:
None
Student records successfully written to file.
If an error occurs, display a meaningful error message.
Required Methods
Your program must include:
● public static void main(String[] args)
● At least one additional method:
Example:
None
public static void writeToFile(List<String> students)
Sample Output in student_records.txt
None
Alice Smith, 1001, Intro to Java, A
Bob Johnson, 1002, Data Structures, B+
Charlie Brown, 1003, Algorithms, C
Diana Prince, 1004, Operating Systems, A-