I'm working on a project for class that reads a txt file of movie-titles, genres, and quantity into a dvd rental system. Using a GUI I have the user select the txt file to be read, check to make sure it's a txt file, and then send it to a constructor to parse information. I'm getting the error response "Bad file name".
Here's the GUI code:
public MyFlixGUI() throws MissingFileException { JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); rentals = new DVDRentalSystem(file.getName()); } else throw new MissingFileException("No file selected."); }
Here's the constructor:
public DVDRentalSystem(String filename){ inventory = new Linklist(); reserve = new Linklist(); athome = new Linklist(); try{ FileReader fr = new FileReader(filename); BufferedReader input = new BufferedReader(fr); String line = input.readLine(); while (line != null){ Scanner scan = new Scanner(line); int inv = scan.nextInt(); String genre = scan.next(); String name = scan.nextLine(); addToInventory(new Film(name,genre,inv)); line = input.readLine(); } } catch (FileNotFoundException e) { System.err.println("Bad file name"); } catch (IOException e) { System.err.println("Exception in reading from file"); } }