Question: Hello...i was struugling trying to get my program to read my file correctly. I got the code to compile correctly, however it reads the file

Hello...i was struugling trying to get my program to read my file correctly. I got the code to compile correctly, however it reads the file incorrectly...I need the file to say Hello COSC 455! as it says in the input file. For some reason it leaves out the 'H' in Hello. The rest runs more or less as it should and the .txt file is correct as well. please help me find the error in my code. The final image is what my program should read
 Hello...i was struugling trying to get my program to read my
file correctly. I got the code to compile correctly, however it reads
the file incorrectly...I need the file to say Hello COSC 455! as
this is the following output:
it says in the input file. For some reason it leaves out
it should look like this....
the 'H' in Hello. The rest runs more or less as it
Please Help

import java. util. Scanner; import jova. Lo. FileReader; import java, io. BufferedReader: import Java, io. IOException; public class Project \{ private Scanner scanner; private int currentline; private int currentColum; private char currentChar; private BufferedReader reader; public static void main(String args) throws IOException f Scanner input = new Scanner(System. in); String filename ="; Project reader = new Project(); do \{ System, out.print("Enter filenane (or \"quitl" or \"exitl" to quit): "); BufferedReader br = new BufferedReader(new java, io. InputStreamReader(System. in)); filenome = br. readline O; if (Ifilename,equals("quit") \&s Ifilenase.equals("exit")) \{ reader. openFile(filenane); while (Ireader. currentCharO. equals("end-of-text")) f reoder. nextChar O; System.out, println(reader,pesitionO +++ reader. currentChar()): \} \} else \{ System, out.println("Error: file not found"); currentColumn =1; nextChar(); // Initialize the currentChar field \} public void nextChar() throws IOException \{ I/ Read the next character from the file int c= reader. read(O; if (c=1){ // End of file reached currentChar =10 '; \} else \{ currentchar = (char) c; currentColumnt+; if (currentChar = ' n ') \{ // Newline character encountered currentlinet+; currentColumn =0; 3 \} \} public String currentChar() \{ if (currentChar = ' 10 ) \{ return "end-of-text"; \} else \{ return Character. tostring(currentChar); \} \} public String positionO \{ return currentline +":"+ currentColumn; 3 Enter filename (or "quit" or "exit" to quit): 1:1 e 1:21 1:31 1:40 2:0 2:1C 2:20 2:3S 2:4C 2:5 2:64 2:75 2:85 2:9 ! 2:9 end-of-text Enter filename (or "quit" or "exit" to quit): The reader should produce the following output: 1:1H1:2e1:311:411:502:02:1C2:202:3S2:4C2:52:642:752:852:9

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!