Error in file is :- java.io.FileNotFoundException: \files\storetime.txt (The system cannot find the path specified)

本小妞迷上赌 提交于 2019-12-12 05:26:55

问题


i am using eclipse for develop the java desktop application and working with file but got the above error

my code is as following please try to help me how to give path in eclipse and also get same problem to load image from the given task

i have put the "files" folder out side the "src" folder

how to give path dynamically

my code is ass following

          public int getTimeId()
{
    LOG.info("The File name is :- " + fileName);
    LOG.info("The path is :- ");
    int count=0;
    FileInputStream fileInputStream;
    ObjectInputStream objectInputStream;
    try
    {
        fileInputStream=new FileInputStream("/files/storetime.txt");
        objectInputStream=new ObjectInputStream(fileInputStream);
        while(objectInputStream.readObject()!=null)
        {
            count++;
        }
    }
    catch(IOException e)
    {
        System.out.println("Error in file is :- " + e);
    } catch (ClassNotFoundException e) {
        System.out.println("Error in class not found :- " + e);
    }
    return count;
}
}

回答1:


You are providing the absolute path by prep-ending / in the path. It means root directory in Unix file system. so, you have to give a relative path of the file from the current directory.You can put files directory in the root directory of your project folder and use

fileInputStream=new FileInputStream("files/storetime.txt");

So, it will be picked up




回答2:


Use FileInputStream(new File("files/storetime.txt")); don't use /file -> it will check for /file partition in linux as /root



来源:https://stackoverflow.com/questions/22654041/error-in-file-is-java-io-filenotfoundexception-files-storetime-txt-the-sys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!