string - Comparing content with file in Java -
I am trying to take as a word input and checking whether that word is in a text file Exists or not. But I ended up with this error
import java.io. *; Public class spell checker {throws public static zero test (string SRR) IOException {FileReader fr = New FileReader ("wordsEn.txt"); Buffett reader BR = new buffed reader (FR); Int i = 0, j = 0, n = str.length (); Str + = ''; String floating = "", temp2 = ""; Do {for (i = j; str.charAt (i)! = ''; I ++) temp + = str.charAt (i); Println (temporary); While ((temp2 = br.readLine ()) = null!) {If (temp == temp2) System.out.print ("\ t \ t \ penis"); Else system.out.print ("\ t \ t \ tWRONG"); } Temp = ""; J = i + 1; } While (i & lt; n); Fr.close (); } Public static zero master (string [] args throws IOException {java.util.Scanner input = new java.util.Scanner (System.in); System.out.print ("Enter the string for which you want to check spelling:"); Letter strng = input.nextLine (); Test (strng); }}
error
Exception in formula "main" java.io.FileNotFoundException: wordsEn.txt (system can not find the file specified) Java.io.FileInputStream.open (Native Method) on java.io.FileInputStream. & Lt; Init & gt; (FileInputStream.java:131) at java.io.FileInputStream. & Lt; Init & gt; (FileInputStream.java:87) In Java Io.FileReader. & Lt; Init & gt; (FileReader.java:58) SpellingChecker.test (SpellingChecker.javaitter) on SpellingChecker.main (SpellingChecker.java29)
the file will not be named only. You must specify the path of the file during creating the" FileReader "object. For example, if the path is" C: \ wordsEn.txt ", You should write: -
FileReader fr = new FileReader (new file ("C: //wordsEn.txt"));
Remember, if you use '\' instead of "/" "Invalid escape character" then error will be visible. It should fix it. Try it ...
Comments
Post a Comment