Search Results

Search found 1 results on 1 pages for 'hmg'.

Page 1/1 | 1 

  • why isn't the input text file being read into the ArrayList<String>, diary?

    - by hmg
    Here's my code: public void readFile() throws IOException { System.out.println("Input file name: "); Scanner in = new Scanner(System.in); String readName = in.nextLine(); Scanner reader = new Scanner(new File(readName)); System.out.println("Reading file..."); while (reader.hasNextLine()) { System.out.println(reader.nextLine()); } System.out.println("File read."); Scanner inAgain = new Scanner(System.in); System.out.println("Would you like to read this into the current Diary?"); System.out.println("Warning: This will overwrite your current Diary!"); String readFileConfirm = inAgain.nextLine(); ArrayList<String> readData = new ArrayList<String>(); if (readFileConfirm.equalsIgnoreCase("yes")) { for (int i = 0; i < readData.size(); i++) { readData.add(reader.nextLine()); } System.out.println("Data added to extra array..."); System.out.println("Here are the contents."); for (int i = 0; i < readData.size(); i++) { System.out.println(readData.get(i)); } System.out.println("Contents read."); System.out.println("Now overwriting current Diary with read file..."); diary.clear(); for (int i = 0; i < diary.size(); i++) { diary.add(readData.get(i)); } System.out.println("New Diary created!"); System.out.println("Use 'recall' to see your new Diary!"); } else { System.out.println("Very well, returning to first command entry."); } } Thanks in advance! -h

    Read the article

1