I cannot find my error. I am getting the classic error....
--------------------Configuration: <Default>--------------------
E:\Object Java\Assignments\Assignment 5\Binary.java:80: 'else' without 'if'
else if(bt.equalsIgnoreCase("t")){
^
1 error
Process completed.
I know it is a problem with my if, else if statements. However, I cannot figure out where the problem is. I think it is where the if connects with the else if when selected b or t. (I have a few other classes to go with this code but for space saving, I didn't include them).
Can anyone please help me. I've been working on this code for two days and I can't find the error!
Also when I paste the code in, it screws up my identation.
import java.io.*; import java.util.Scanner; public class Binary implements Serializable{ public static void main(String[] args) { boolean dofile = true; String yn = "n", fname = "", bt = "b", rw = "r", line = ""; PrintWriter textOut = null; ObjectOutputStream binaryOut = null; ObjectOutputStream outputStream = null; ObjectInputStream inputStream = null; OutputText mto = null; OutputBinary mbo = null; Scanner keyboard = new Scanner(System.in); do{ System.out.println("Enter the file name."); fname = keyboard.nextLine(); System.out.println("Chose binary or text file (b/t):"); bt = keyboard.nextLine(); if(bt.equalsIgnoreCase("b"));{ mbo = new OutputBinary(fname); binaryOut = mbo.createBinaryFile(); System.out.println("Chose read or write (r/w):"); rw = keyboard.nextLine(); if (rw.equalsIgnoreCase("r")){ try{ inputStream = new ObjectInputStream(new FileInputStream(fname)); String binaryOut = inputStream.readUTF(); System.out.println("File contains..." + binaryOut); } catch (IOException e){ System.out.println("The file is blank, please write in it."); } binaryOut.close(); } else if(rw.equalsIgnoreCase("w")){ do{ System.out.println("Enter a line of information to write to the file:"); try{ line = keyboard.nextLine(); binaryOut.writeObject(line); outputStream.flush(); outputStream.close(); } catch(IOException e){ System.out.println("Problem writing to file."); } System.out.println("Would you like to enter another line? (y/n)"); yn = keyboard.nextLine(); if(yn.equalsIgnoreCase("n")) dofile = false; }while(dofile); } } else if(bt.equalsIgnoreCase("t")){ mto = new OutputText(fname); } System.out.println("Chose read or write (r/w):"); rw = keyboard.nextLine(); if(rw.equalsIgnoreCase("r")){ try{ BufferedReader inputStream = new BufferedReader(new FileReader(fname)); } catch (IOException e){ System.out.println("You have to write something in a file before you can read it!"); } System.out.println("File contains: " + fname); char next = (char)inputStream.read(); textOut.close(); } else if(rw.equalsIgnoreCase("w")){ do{ System.out.println("Enter a line of information to write to the file:"); try{ line = keyboard.nextLine(); textOut = new PrintWriter(new FileOutputStream(fname)); textOut.println(line); outputStream.flush(); outputStream.close(); } catch(IOException e){ System.out.println("Problem writing to file."); } System.out.println("Would you like to do another file? (y/n)"); yn = keyboard.nextLine(); if(yn.equalsIgnoreCase("n")) dofile = false; }while(dofile); } System.out.println("Would you like to do another file? (y/n)"); yn = keyboard.nextLine(); if(yn.equalsIgnoreCase("n")) dofile = false; }while(dofile); } }