Java FileNotFoundException错误

Java FileNotFoundException错误,java,javabeans,Java,Javabeans,当我试图复制.pdf文件时,我得到了FileNotFoundException,我在我的框架中使用了这种编码。这是我在框架中编码的一部分。任何人都可以帮我。如果你需要任何其他信息,尽管问我 public void copyFile(String dir, String file) { try{ Debug.println("System.getProperty(\"reporthome\")"+System.getProperty("reportho

当我试图复制.pdf文件时,我得到了FileNotFoundException,我在我的框架中使用了这种编码。这是我在框架中编码的一部分。任何人都可以帮我。如果你需要任何其他信息,尽管问我

 public  void copyFile(String dir, String file) {

        try{
            Debug.println("System.getProperty(\"reporthome\")"+System.getProperty("reporthome"));
            File path = new File(System.getProperty("reporthome")+"\\jreports\\fileimport\\"+file);
            FileInputStream fis = new FileInputStream(path);
            Debug.println("dir+\"\\\\\"+file"+dir+"\\"+file);
            FileOutputStream fos = new FileOutputStream(dir+"\\"+file);
            int i = 0;
            while( (i = fis.read()) != -1){
                fos.write(i);
            }
            fis.close();
            fos.close();
            path.delete();
        }catch(IOException io){
            Debug.println(" Exception while copying file: "+io);
        }

     }
试试这个

public  void copyFile(String dir, String file) {

    try{
        Debug.println("System.getProperty(\"reporthome\")"+System.getProperty("reporthome"));
        File path = new File(System.getProperty("reporthome")+"\\jreports\\fileimport\\"+file);
    if (path.exists()){ 
        FileInputStream fis = new FileInputStream(path);
        FileOutputStream fos = new FileOutputStream(dir+"\\"+file);
        int i = 0;
        while( (i = fis.read()) != -1){
        fos.write(i);
        }
        fis.close();
        fos.close();
        path.delete();
     } else{
    Debug.println("Path doesn't exist : "+ path);
     }

    }catch(IOException io){
        Debug.println(" Exception while copying file: "+io);
    }

 }

您确定要从中复制文件的目录中有该文件吗?你能调试你的代码吗?我的意思是,如果您使用的是Eclipse,那么很容易设置断点并检查代码是否存在此特殊异常。

添加if(path.exists())并检查它是否存在首先用File.separator替换所有“\\”,然后重试找不到哪个文件?文件还是文件路径?