I just experienced this problem. This seems to work just by redesigning the scanner. Replace this:
File file1 = new File("file1"); Scanner in= new Scanner(file1);
with this:
FileReader file1 = new FileReader("file1"); Scanner in= new Scanner(file1);
Perhaps the problem arises when you create a scanner from a file without a system, knowing that it is a text file.
source share