Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Boot应用程序中的java.io.FileNotFoundException_Java_Spring_Spring Boot_Filenotfoundexception - Fatal编程技术网

Spring Boot应用程序中的java.io.FileNotFoundException

Spring Boot应用程序中的java.io.FileNotFoundException,java,spring,spring-boot,filenotfoundexception,Java,Spring,Spring Boot,Filenotfoundexception,我有一个小应用程序,我已经使用了SpringBoot。在这个应用程序中,我读取了一个位于运行这个应用程序的本地系统磁盘中的conf文件 BufferedReader confFile = new BufferedReader(new FileReader("C:\\Users\\userName\\Desktop\\Tes\\conf.json")); 我在指定的位置也有一个conf.json文件。但当我运行我的spring boot应用程序时,它会说 java.io.FileNotFound

我有一个小应用程序,我已经使用了SpringBoot。在这个应用程序中,我读取了一个位于运行这个应用程序的本地系统磁盘中的conf文件

BufferedReader confFile = new BufferedReader(new FileReader("C:\\Users\\userName\\Desktop\\Tes\\conf.json"));
我在指定的位置也有一个conf.json文件。但当我运行我的spring boot应用程序时,它会说

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)
java.io.FileNotFoundException:C:\Users\userName\Desktop\Tes\conf.json(系统找不到指定的文件)
位于java.io.FileInputStream.open0(本机方法)
位于java.io.FileInputStream.open(未知源代码)
位于java.io.FileInputStream。(未知源)
位于java.io.FileInputStream。(未知源)
位于java.io.FileReader。(未知源)
请告诉我我缺少什么

注意:当我从eclipse运行此应用程序时,它不会出现问题。

Classic BufferedReader 从文件中读取内容的经典BufferedReader

E:\test\filename.txt ReadFileExample1.java 输出:
资源链接:

先生,请用try块将其包围,检查权限,确定是否有人可以阅读。实际上,错误是找不到该文件。
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