I have a scanner in my program that reads in parts of a file and formats them for HTML. When I read my file, I need to know how to make the scanner know that it is at the end of the line and start writing to the next line.
Here is the relevant part of my code, let me know if I left something:
//scanner object to read the input file Scanner sc = new Scanner(file); //filewriter object for writing to the output file FileWriter fWrite = new FileWriter(outFile); //Reads in the input file 1 word at a time and decides how to ////add it to the output file while (sc.hasNext() == true) { String tempString = sc.next(); if (colorMap.containsKey(tempString) == true) { String word = tempString; String color = colorMap.get(word); String codeOut = colorize(word, color); fWrite.write(codeOut + " "); } else { fWrite.write(tempString + " "); } } //closes the files reader.close(); fWrite.close(); sc.close();
Well, I found out about sc.nextLine (); but I still don't know how to determine when I am at the end of a line.
source share