问题
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