gpt4 book ai didi

java - 想要以编程方式删除 weblogic 上的临时文件

转载 作者:行者123 更新时间:2023-12-01 04:45:57 29 4
gpt4 key购买 nike

您好,正在使用 weblogic 服务器上传文件。要上传的文件的临时文件正在文件夹 E:\WL\user_projects\domains\AMS_domain\servers\AdminServer\tmp\_WL_user\GenesisDenmark\3m840e\public 中创建。

如果我上传 test.zip,则该文件将以名称 test.tmp 复制到上述位置。我想以编程方式删除它。我使用的是struts 1.1。

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

谢谢!

最佳答案

可能是因为其他原因。你真的想以编程方式删除吗?我可能是错的(如果是,请告诉我),但您可以使用正则表达式来匹配所有临时文件。但更好的方法是,如果每次上传任何文件时都采用文件名,搜索具有相同名称和 .tmp 扩展名的文件。用 File 对象表示该文件,尝试以编程方式获取该特定文件是否存在,然后删除该文件。(在 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 文件。

关于java - 想要以编程方式删除 weblogic 上的临时文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15832291/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com