I am getting a compile error in the following code that I do not know how to fix.
public class Test throws IOException{
public static void main(String[] args) {
String path = "document.txt";
File file = new File(path);
Files.readString(file.toPath()); //cannot find symbol method readString(java.nio.file.Path)
}
}
but I get
Error:(8, 14) java: cannot find symbol
symbol: method readString(java.nio.file.Path)
location: class java.nio.file.Files
There are a number of things to note.
readString(Path)
in java.nio.file.Files
. If I were to try size(Path)
(another method in java.nio.file.Files
), it worksThis code does not work in intelliJ but it works in eclipse
This code works if I create a new project in intelliJ but not in my current Maven project that I cloned from github
I have tried all suggestions here including:
Test.java
It means that the files exist locally, but are not in the repository, and are not scheduled for addition. With other words, the files are not under version control. There is not really a problem since the files can just be added to the VCS if desired.
As Axel's answer pointed out, the problem did have to do with the Java version, but it was not the SDK or language level.
What solved it was by going to File > Settings > Build > Compiler > Java Compiler. I then changed the Project Bytecode Version to 11 and removed Per Module Bytecode Version entries that were set to 10.
Note if this error keeps happening to you, this could be because the source and target version is not specified in your pom.xml. See this question for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With