java - Scanner not working instead of buffered reader -


i'm writing code remove word text file , can't seem scanner work. work bufferedreader i'm not allowed use that. doing wrong here?

    public static void option2method(string dictionary) throws ioexception  {      file inputfile = new file(dictionary);     file tempfile = new file("tempdict.txt");     string tempword = joptionpane.showinputdialog(null, "enter word remove");     string linetoremove = tempword.tolowercase();     linetoremove = linetoremove.replaceall(",", "");     linetoremove = linetoremove.replaceall("\\.", "");     linetoremove = linetoremove.replaceall("\\?", "");     linetoremove = linetoremove.replaceall(" ", "");      scanner reader = new scanner(new file(inputfile));     filewriter writer = new filewriter(tempfile);     string currentline;      while((currentline = reader.hasnext()) != null)     {         string trimmedline = currentline.trim();         if(trimmedline.equals(linetoremove)) continue;         writer.write(currentline + "\n");     }     reader.close();     writer.close();     inputfile.delete();     tempfile.renameto(inputfile); } 

while((currentline = reader.next()) != null) 

use next() instead of hasnext().

hasnext() - if there more token present in input or not.

next() - return next complete token input.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -