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

StackOverflow https://stackoverflow.com/questions/22654041

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;
}
}
有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top