Write a method to save a Linked List to a text file called file.txt. It must sav
ID: 3640376 • Letter: W
Question
Write a method to save a Linked List to a text file called file.txt. It must save the Linked List to the file with each node on a different line.Here is the Linked List
LinkedList<Account> account = new LinkedList<Account>();
Account is the class that contains all of the string information for each account such as username, password, email, state, hobby. But basically this is what the linked List looks like, but with multiple accounts.
John
Password
John@hotmail.com
Virginia
Driving
Explanation / Answer
Impossible to write without access to Account class. In Java style pseudocode:
LinkedList<Account> account;
// open file
PrintWriter fileout = new PrintWriter(new File("file.txt"));
for(Account acc : account)
{
// print data on one line
fileout.println(acc.username+" "+acc.password+" "+account.email+" "+account.state+" "+account.hobby);
}
// save file
fileout.close();
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.