Java 要以编程方式删除weblogic上的临时文件吗

Java 要以编程方式删除weblogic上的临时文件吗,java,Java,使用weblogic服务器上载文件时出现Hi。正在文件夹E:\WL\user\u projects\domains\AMS\u domain\servers\AdminServer\tmp\\u WL\u user\genesisdank\3m840e\public上创建要上载的文件的临时文件 如果我上传test.zip,那么它将以test.tmp的名称复制到上述位置。我想用程序删除它。 我使用的是Struts1.1 如果有人做过类似的事情。请帮忙 谢谢 可能是因为其他原因。是否确实要以编程方式

使用weblogic服务器上载文件时出现Hi。正在文件夹
E:\WL\user\u projects\domains\AMS\u domain\servers\AdminServer\tmp\\u WL\u user\genesisdank\3m840e\public
上创建要上载的文件的临时文件

如果我上传test.zip,那么它将以test.tmp的名称复制到上述位置。我想用程序删除它。 我使用的是Struts1.1

如果有人做过类似的事情。请帮忙


谢谢

可能是因为其他原因。是否确实要以编程方式删除?我可能错了(如果是,请告诉我),但您可以使用正则表达式匹配所有临时文件。但更好的方法是,如果每次上传任何文件时都使用文件名,搜索具有相同名称和.tmp扩展名的文件。用文件对象表示该文件,如果该特定文件存在,则尝试以编程方式获取该文件并删除该文件。(在struts中,您应该在Action类中执行此操作,或者如果您将spring/EJB与struts一起使用,则应该在业务逻辑中执行此操作。) 我认为您需要执行以下步骤

 1. Fetch the uploaded file name(As I think it will be with extension)
 2. get a substring of this file name upto the last location of . (to
    get the file name without extension)
 3. append .tmp in that file name
 4. check the condition if that file exists in your uploading directory
 5. if so, delete the file
一些示例代码,希望对您有所帮助:

        //Get the servers upload directory real path name
          filepath = getServletContext().getRealPath("/")+"xml_upload";
          System.out.println("The file path is "+filepath);
          //create the upload folder if not exists
           File folder = new File(filepath);
           if(!folder.exists())
           {
            folder.mkdir();
           }


     MultipartRequest m=new MultipartRequest(req,filepath);
     ff=m.getFile("f");
     System.out.println("Full Path with file name:"+ff);
     //get file name...
     filename=ff.getName();
     System.out.println("file name is:"+filename);

      //now here you have to get the file name without extension and then append the extension .tmp
 // now let the file is represented by a File object say ff .....

   if(ff.exists())
          {
           System.out.println("File exist and it is going to delete.");
           ff.delete() ;
           }

对于我的一个XML上传应用程序,我使用了相同的方法,因为XML数据将被更新,新的值将被显示,如果用户想在单击“放弃”按钮时放弃XML文件所做的更新,它将恢复更改并删除上传的XML文件。

Hey Shailesh感谢您的帮助。但我只是检查了一下临时文件是否在一段时间后自动删除。我的问题是在上传文件之前删除浏览器的缓存/历史记录。因为我的任务是上传一个巨大的文件,但由于broswer或表单已经包含了巨大的数据,所以在上传文件时会出现多部分错误(这是我对获取多部分错误的理解)。多部分错误可能还有其他原因。请确保在表单标记中保留enctype=multipart/form数据。第二件事是清除浏览器的缓存,您可以在head标记中使用它,并在每个jsp中使用它,在加载时清除缓存。我已经在代码中使用了上述标记。但是我想这些标签是为了不让我的文件被缓存。我想删除以前存在的缓存。因此,该表单并不沉重。据我所知,“想删除以前存在的缓存”毫无意义!至于一次,您可以手动执行,之后它将不会在缓存中存储任何内容,因为您将头设置为不将其存储在缓存中。你可以查看这些链接:如果对你没有帮助,请让我知道。因为随时欢迎你。