我有一个小应用程序,我使用过春季启动。在这个应用程序中,我读了一个位于本应用程序运行的本地系统磁盘中的conf文件。
BufferedReader confFile = new BufferedReader(new FileReader("C:\\Users\\userName\\Desktop\\Tes\\conf.json"));
我在指定位置也有一个conf.json文件。但是,当我运行我的春季启动应用程序时,它说
java.io.FileNotFoundException: C:\Users\userName\Desktop\Tes\conf.json (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
请告诉我我错过了什么。
注意:当我从eclipse运行这个应用程序时,它运行没有问题。
答案 0 :(得分:0)
用于从文件中读取内容的经典BufferedReader。
This is the content to write into file
This is the content to write into file
package com.mkyong;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ReadFileExample1 {
private static final String FILENAME = "E:\\test\\filename.txt";
public static void main(String[] args) {
BufferedReader br = null;
FileReader fr = null;
try {
fr = new FileReader(FILENAME);
br = new BufferedReader(fr);
String sCurrentLine;
br = new BufferedReader(new FileReader(FILENAME));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
This is the content to write into file
This is the content to write into file