Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.io.FileNotFoundException:/u01/app/webapps/out/pj/Create.xlsx_Java_Excel_File_Filenotfoundexception_Fileoutputstream - Fatal编程技术网

java.io.FileNotFoundException:/u01/app/webapps/out/pj/Create.xlsx

java.io.FileNotFoundException:/u01/app/webapps/out/pj/Create.xlsx,java,excel,file,filenotfoundexception,fileoutputstream,Java,Excel,File,Filenotfoundexception,Fileoutputstream,我试图比较两个excel文件的上次修改日期,并用新文件替换旧文件 在场景中:当一开始没有文件时,代码会将文件复制到该位置,然后读取 问题是:当服务器上不存在excel文件时,即使在将文件写入数据库后,它也会引发FileNotFound异常 服务器(通过代码),但在服务器上看不到该文件。它对你有用 我的机器(windows),但在服务器上部署时失败 同样,当文件出现在服务器上时,当旧文件被新文件替换时,它会像魅力一样工作 您能否帮助并解释一下为什么它在上述场景中失败,并且只在服务器上失败 if(r

我试图比较两个excel文件的上次修改日期,并用新文件替换旧文件

在场景中:当一开始没有文件时,代码会将文件复制到该位置,然后读取

问题是:当服务器上不存在excel文件时,即使在将文件写入数据库后,它也会引发
FileNotFound异常
服务器(通过代码),但在服务器上看不到该文件。它对你有用
我的机器
(windows)
,但在服务器上部署时失败

同样,当文件出现在服务器上时,当旧文件被新文件替换时,它会像魅力一样工作

您能否帮助并解释一下为什么它在上述场景中失败,并且只在服务器上失败

if(row.getValue("fileType").toString().equals("xlsx")&&checkindatefolder.after(localdate))
                {
                messagelist.add("we are going to get the replace file in the server");


            InputStream inp=folder.getFile();
            ZipInputStream izs = new ZipInputStream(inp);
            ZipEntry e = null;
            while ((e = izs.getNextEntry()) != null) {
                System.out.println("e.isDirectory(): "+e.isDirectory());
            if (!e.isDirectory()) {
                    filename=e.getName();
                    System.out.println("filename: "+filename);
                    FileOutputStream os=new FileOutputStream("path"+e.getName());
                    byte[] buffer = new byte[4096];
                    int    read=0;
                    System.out.println("writing to file");
                    while ((read=izs.read(buffer))> 0) {
                        System.out.println("1111");
                        os.write(buffer,0,read);
                    }
                    System.out.println("writing to file complete");
                    inp.close();
                    os.flush();
                    os.close();
                }
            }

路径的所有部分都存在吗

在你的例子中:

/u01/app/webapps/out/pj/Create.xlsx
所有子目录都存在吗

/u01/app/webapps/out/pj
否则,尝试写入可能会失败,出现
FileNotFoundException


您应该使用
文件创建目录。首先创建目录(路径)

FileOutputStream正在等待文件路径作为参数:
new FileOutputStream()我已将路径硬编码为-private String path=“/u01/app/webapps/out/pj/”;在这种情况下,它不应该在文件存在的第二种情况下工作,对吗?这是windows还是linux路径?这是linux路径。但是在使用windows时,我使用了另一个带有“//”的路径。是的,所有子目录都存在,出于同样的原因,其他场景也可以工作。新文件将替换旧文件。@naRen您的服务器上运行的是什么操作系统?服务器在Red Hat 4.1.2-52上运行linux@naRen运行代码的进程是否有权访问该目录?是。。我们能够读写一个新文件到目录中,但只有在旧版本存在的情况下。只有当前面没有文件时,它才会失败。