I am new to java and having issues compiling my code. I continue to receive two errors that FileReader is not a statement and that a ";" is expected after FileReader. I have tried to import several tools but I am still having trouble. I am running java version 1.6.0_35-b10, could this be the problem?
Here are the errors:
----jGRASP exec: javac -g lab12.java
lab12.java:61: not a statement
FileReader ifile = new FileReader("data.txt");
^
lab12.java:61: ';' expected // the arrow points after FileReader
FileReader ifile = new FileReader("data.txt");
^
2 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
This is my code:
import java.util.Scanner; import java.text.*; import java.io.*; import java.io.FileReader; import java.io.File; public class lab12 { public static void main(String[] args){ int c; String line; Foreign calculator; Scanner Keyboard = new Scanner(System.in); FileWriter ofile = new FileWriter("data.txt"); BufferedWriter bw = new BufferedWriter(ofile); PrintWriter outfile = new PrintWriter(ofile); do { Foreign.displayTitle(); Foreign.displayMenu(); c = Foreign.getChoice(); //<----- Call getChoice() here and assign value to ‘c’ if ( c != 0) { calculator = new Foreign(); calculator.getAmount(); calculator.display(); outfile.println(calculator); //<---- calls toString() implicitly } } while (c != 0); outfile.close(); System.out.print("Display summary? (y/n)"); s = keyboard.nextLine(); displaySummary = s.charAt(0); if (displaySummary == 'Y' || displaySummary == 'y') FileReader ifile = new FileReader("data.txt"); BufferedReader infile = new BufferedReader(ifile); while ((line = infile.readLine()) != null) { System.out.println(line); } infile.close(); Foreign.displayCount(); } }