文件中的错误是: - java.io.FileNotFoundException:\files\storetime.txt(系统找不到指定的路径) [英] Error in file is :- java.io.FileNotFoundException: \files\storetime.txt (The system cannot find the path specified)

查看:238
本文介绍了文件中的错误是: - java.io.FileNotFoundException:\files\storetime.txt(系统找不到指定的路径)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用eclipse来开发Java桌面应用程序和使用文件,但得到了上述错误

我的代码如下,请尽量帮助我如何给在Eclipse中的路径,也得到同样的问题,从给定的任务加载图像

我已经把文件文件夹放在src文件夹外面$ /

如何动态地给路径

我的代码是屁股跟着

 public int getTimeId()
{
LOG.info(文件名是: - + fileName);
LOG.info(The path is: - );
int count = 0;
FileInputStream fileInputStream;
ObjectInputStream objectInputStream;
尝试
{
fileInputStream = new FileInputStream(/ files / storetime.txt);
objectInputStream = new ObjectInputStream(fileInputStream);
while(objectInputStream.readObject()!= null)
{
count ++;

$ b catch(IOException e)
{
System.out.println(Error in file is: - + e);
} catch(ClassNotFoundException e){
System.out.println(找不到类中的错误: - + e);
}
return count;



$ div $解析方案

通过在路径中准备结束 / 来提供绝对路径。这意味着Unix文件系统中的 root 目录。因此,您必须从当前目录中提供文件的相对路径。您可以将 files 目录放在项目文件夹的根目录中,并使用

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

所以,它会被拿起


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

这篇关于文件中的错误是: - java.io.FileNotFoundException:\files\storetime.txt(系统找不到指定的路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆