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.
- This only happens for
readString(Path)
injava.nio.file.Files
. If I were to trysize(Path)
(another method injava.nio.file.Files
), it works This 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:
- Build > Rebuild Project
- Recompiling just
Test.java
- File > Invalidate Caches
- Checked the /src folder is marked as source folder
- Reimporting Maven dependencies