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

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

Pergunta

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;
}
}
Foi útil?

Solução

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

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top