I need to demonstrate to customers locally importing data from postgresql into elasticsearch. I wrote a program read3.java in idea. There is no problem reading the file content with scanner.
But this read3.java is only used to convert the json file exported by the table into a valid json file that can be imported into es, and does not add the dependency that needs to be downloaded, but I have to do it in the idea every time I run it.
So I directly found the target path of read3.java and copied it to the desktop.
Compile a .class file with javac directly on the desktop and then start running.
Every time there is an error, that is
Exception in thread “main” java.util.NoSuchElementException
Then I reopened the notepad and created an abc.json file, saved the encoding format as “utf-8”, and then used read3 to read the file, and the read out was garbled.
So I thought that there is a problem with the encoding of the characters read by the scanner. When creating the scanner, specify the encoding, that is, Scanner sc=new Scanner(new FIle(“xxx”),”utf-8″));
Then use notepad++ to open the file that needs to be read, and find that the file encoding is utf-8 bom, so I converted the encoding format to utf-8 and re-run. The problem is solved.
- How to Solve Error: Scanner class java. Util. NoSuchElementException exception
- Error log: resource leak: ‘xxx’ is never closed (precautions for scanner class)
- Solution to the error of failed to create JVM in idea startup
- Solution to the problem of Java program “resource leak: ‘SC’ is never closed” in vscode
- [Solved] Jedis Error: NoSuchElementException: Timeout waiting for idle object
- [Solved] TypeError: string indices must be integers, not str
- [Solved] idea Remote Submit spark Error: java.io.IOException: Failed to connect to DESKTOP-H
- [Solved] org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key
- [Solved] Redis Operation exception: java.lang.ClassCastException: java.lang.Long cannot be cast to [B