我試圖讀取從屬性讀取的文件路徑中的文件,但我不斷收到FileNotFoundException(該文件存在)。從屬性文件讀取文件路徑
test.properties:
test.value = "src/main/resources/File.csv"
LoadProperties.java:
public class LoadProperties {
public static void main(String[] args) throws FileNotFoundException, IOException {
Properties aProp = new Properties();
aProp.load(new FileInputStream("src/main/resources/test.properties")); // works
String filepath = aProp.getProperty("test.value");
System.out.println(filepath); // outputs: "src/main/resources/File.csv"
FileReader aReader = new FileReader("src/main/resources/File.csv"); // works
FileReader aReader2 = new FileReader(filepath); // java.io.FileNotFoundException
}
}
,而它上面的行工作得很好,爲什麼被拋出此異常? 如何從屬性提供的路徑中讀取文件?