Trying to write a simple application that reads a file and prints out the file's content. I read that Java 11 has Java.io.file library so I used it. I created a .txt file locally.
My main class looks like this:
package com.iz.backend;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
import javax.swing.text.AbstractDocument.Content;
@SpringBootApplication
public class BackendApplication {
public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
Path filePath = Paths.get("/Users/iz/Proj/backend/src/testFile.txt");
try
{
String content = Files.readString(filePath);
System.out.println(content);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
When running
mvn clean install
to compile and build a jar file, I get a compilation error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project backend: Compilation failure
[ERROR] /home/proj/backend/src/main/java/com/iz/backend/BackendApplication.java:[26,34] error: cannot find symbol
[ERROR]
[ERROR] -> [Help 1]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…