Hi! I'm fairly new to Java, or even programming in general. I'm using Netbeans to help me find errors and everything, but when I try to run/debug my program, It says there is something wrong with my 'while' loop. Can I have some pointers?
Main.java
class Main{ public static void main(String[] args){ filereader fr = new filereader(); fr.openFile(); fr.readFile(); fr.closeFile(); } }
filereader.java
import java.io.*; import java.util.*; public class filereader{ private Scanner scan; public void openFile(){ File codes = new File("codes.txt"); try{ scan = new Scanner(codes); } catch(Exception e){ System.out.println("Couldn't find file."); } } public void readFile(){ while(scan.hasNext()){ String num = scan.next(); String code = scan.next(); System.out.println(num + code); System.out.println(); System.out.println("Press Enter to continue..."); Scanner input = new Scanner(System.in); input.nextLine(); } } public void closeFile(){ scan.close(); } }
codes.txt
1. 3RXPM3 2. 26MYKD 3. 5GATBA 4. PMF5R3 5. 3SJUPQ 6. NBR5JT 7. PUR3VR 8. AJJCF2 9. NCM26A 10. MT2Y5G 11. FG43PK 12. GMBH87 13. T9HMHN 14. RCYMKW 15. 36E9FU 16. FBRKJ2 17. YAPG32 18. MMR2X4 19. A7NAR9 20. N62VRX 21. NV4A65 22. KGFDT2 23. RFWMVE 24. F465F9 25. 7KPU67 26. 2E8V7U 27. CJWBD7 28. 49E5P8 29. WUEUAU 30. TN45G2 31. 5D7FY8 32. T9JT8V 33. Y4JEPT 34. 84GYTY 35. 265B3X 36. JA6G58 37. 4YWTBU 38. Y8US2D 39. 7794YU 40. TWDP3R 41. H7VDPY 42. KBJN38 43. QPT4Q 44. EKT6JJ 45. YWTBUC 46. TERKP9 47. HUDG6T 48. 4CCS9S 49. UN4SRA 50. UQXSST 51. BPUK82 52. 88D544 53. 6C2T7S 54. T4GTGJ 55. HJ7PR5 56. 7BCDV9 57. XRSVRA 58. P973MD 59. S5AYPJ 60. JC4STS 61. 44MA2X 62. UY4QDJ 63. 44DMRR 64. Q6AD5N 65. H3UGEG 66. F4VHWU 67. 4689TU 68. JR8EHW 69. FVGAJP 70. 86KF9N 71. 5KA8FM 72. U6B37E 73. 9W8PEQ 74. CV949U 75. BX7AXS 76. 8JVG2F 77. 2HAJ9X 78. 3AS3RP 79. XWEQ4Q 80. GPN77T 81. RD36SS 82. U2FE5W 83. QT5SQJ 84. VUDJT7 85. 28KKJN 86. 72H3MB 87. 9JY5CX 88. KM6QFC 89. PTVSYU 90. 9VGC9W 91. MRR7PM 92. VVH88A 93. YNQW5R 94. PMGCN8 95. X3YTDW 96. S22N2J 97. A37W4N 98. TDJQFH 99. VA7TAS 100. 7TE866