简体   繁体   English

从Java Applet中的Jar文件中提取文件

[英]Extract Files from Jar file in Java Applet

I have a java applet that contains resources directory (Directory name is: Resources) this directory contains some dll files. 我有一个Java applet,其中包含资源目录(目录名称:Resources),该目录包含一些dll文件。 (This directory/folder is packaged in the jar file for the applet). (此目录/文件夹打包在applet的jar文件中)。

I am trying to extract the contents of this directory to the local hard disk. 我正在尝试将该目录的内容提取到本地硬盘上。 I am using 我在用

getClass().getClassLoader().getResourceAsStream("Resources/" + fileName);

to get the file and save it to another path so i can access it. 获取文件并将其保存到另一个路径,以便我可以访问它。 This method is working before deploying/embedding my applet to a HTML page. 在将小程序部署/嵌入到HTML页面之前,此方法有效。

I Have two problems: 我有两个问题:

1- After deploying on a web server, this method returns null. 1-在Web服务器上部署后,此方法返回null。

2- How to enumerate all files in the resources folder after deploying my applet, so that i can save these files to another path. 2-部署小程序后如何枚举资源文件夹中的所有文件,以便我可以将这些文件保存到其他路径。

Sorry if my question is stupid, simple or unclear because this is the first Java applet for me. 很抱歉,我的问题是愚蠢,简单还是不清楚,因为这是我的第一个Java applet。

I am suggesting an alternative for your second question. 我建议您为第二个问题提供替代方案。 You could run OS commands in your java code to do these operations. 您可以在Java代码中运行OS命令来执行这些操作。 If you are on a linux environment to extract the whole folder and copy somewhere else you can run 如果您在Linux环境中提取整个文件夹并复制到其他位置,则可以运行

jar xf yourjarfile.jar Resources
cp -rf Resources toSomewhereElse/

in your java code. 在您的Java代码中。 You can find examples here to see how to run OS commands in your Java code. 您可以在此处找到示例以了解如何在Java代码中运行OS命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM