Can anyone see why this makes my Java servlet hang? Compiles but CPU goes to 100% so I'm assuming there's an infinite loop somewhere..?
quotes.txt only has 10 lines.
String line = "";
try {
String filePath = new File("").getAbsolutePath();
filePath += "/quotes.txt";
Scanner scan = new Scanner(filePath);
int lines = 0;
while (scan.hasNextLine()) {
lines++;
}
Random random = new Random();
int randomInt = random.nextInt(lines);
for (int i = 0; i < randomInt; i++) {
line = scan.nextLine();
}
scan.close();
} catch (Exception e){
line = e.getMessage();
}
Thanks