Question
JAVA: Please help me fix my error( see my code below) I need read and write the text file. please fellow the instruction inFile (use
JAVA: Please help me fix my error( see my code below) I need read and write the text file. please fellow the instruction
inFile (use argv[1]): A text file contains a list of English words (strings), giving below
outFile1 (use argv[2])a text file includes
i) The completed sorted linked list, in ascending order.
//With caption indicating you are printing the original sorted list
ii) The reversed linked list.
//With caption indicating you are printing the reversed sorted list
outFile2( use argv[3]): All debugging outputs.
my code:
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();
}
}
}
string list in a text file:
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started