Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors.

Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors. below is my code

import java.io.FileInputStream;

import java.io.InputStreamReader;

import java.io.FileWriter;

import java.io.IOException;

public class LinkedList

{

Node head;

class Node

{

int data;

Node next;

Node(int d)

{

data = d;

next = null;

}

}

void printMiddle()

{

Node slow_ptr = head;

Node fast_ptr = head;

if (head != null)

{

while (fast_ptr != null && fast_ptr.next != null)

{

fast_ptr = fast_ptr.next.next;

slow_ptr = slow_ptr.next;

}

System.out.println("The middle element is [" +

slow_ptr.data + "] ");

}

}

public void push(int new_data)

{

Node new_node = new Node(new_data);

new_node.next = head;

head = new_node;

}

public void printList()

{

Node tnode = head;

while (tnode != null)

{

System.out.print(tnode.data+"->");

tnode = tnode.next;

}

System.out.println("NULL");

}

public class TextFileReadingAndWriting {

public static void main(String[] args) {

try {

FileReader reader = new FileReader("MyFile.txt");

try {

FileWriter writer = new FileWriter("MyFile.txt", true);

BufferedReader bufferedReader = new BufferedReader(reader);

String line;

while ((line = bufferedReader.readLine()) != null) {

System.out.println(line);

}

reader.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

this is string list in a text file which I like to read:

Hishaam Esteban Kevin

Matthew Brandon

Joel Luis Jianwei Yechiel

Taeyong

Jiayu

Jiade Phillip

Russell Mohebullah

Akshar Evgeniia Andres Marco Justin

Robin Kelvin Zhiheng Jeffrey

Yifei Yinyu

Jiaxin Youyia Eleftherios

Yuan

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

b. Explain how you initially felt about the communication.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago