Java scanner reading garbage
问题 I am reading a text file using java Scanner. try { while(sc.hasNextLine()) { //Read input from file inputLine = sc.nextLine().toUpperCase(); System.out.println(inputLine); } The above gives below output while my text file only includes "aabbcc". How to avoid scanner from scanning the garbage? Thanks. {\RTF1\ANSI\ANSICPG1252\COCOARTF1265\COCOASUBRTF210 {\FONTTBL\F0\FSWISS\FCHARSET0 HELVETICA;} {\COLORTBL;\RED255\GREEN255\BLUE255;} \PAPERW11900\PAPERH16840\MARGL1440\MARGR1440\VIEWW10800