我写了一个签名的小程序,它可以接收文件并将其写入本地机器文件目录。我使用 NetBeans 在 Windows 7 上工作。在 Appletviewer 中一切运行正常。但是当我在 Web 浏览器中的网页上下文中运行小程序时,小程序可以在本地目录中创建一个文件,但我不能copyFile()
使用apache common.io
. 我可以写入使用创建的文件bufferedWriter()
,但不能使用fileWriter
. 我需要使用Java 库中的将文件从.wav转码为.mp3Encoder
,但它在浏览器中不起作用。(我尝试了用户主文件夹和其他文件夹,但结果是一样的。)
这是我尝试实现文件复制的代码。不会抛出异常,但文件也不会被复制。
try {
FileUtils.copyFile(source, target);
} catch(IOException e){
jLabel4.setText("Error: " + e.getMessage());
}
我可以捕获异常,所以当我按下应该复制的按钮时,这是来自我的 Java 控制台的文本:
try { FileUtils.copyFile(fl1, fl2); } catch (IOException ex) { ex.printStackTrace(); jLabel4.setText("Error: " + ex.getMessage()); }
这是我的 java 控制台文本:
basic: Told clients applet is started
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Connecting http://localhost:8084/ with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Connecting http://localhost:8084/Rozhlas_jsf/lib/commons-io-2.4.jar with proxy=DIRECT
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/, version: null]
network: Cache entry not found [url: http://localhost:8084/Rozhlas_jsf/org/apache/commons/io/FileUtils.class, version: null]
network: Connecting http://localhost:8084/Rozhlas_jsf/org/apache/commons/io/FileUtils.class with proxy=DIRECT
Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
at SoundApplet.SoundApplet.jButton2ActionPerformed(SoundApplet.java:480)
at SoundApplet.SoundApplet.access$800(SoundApplet.java:42)
at SoundApplet.SoundApplet$11.actionPerformed(SoundApplet.java:304)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 38 more
导入库似乎有些不好。我通过右键单击库文件夹添加罐子并添加罐子。我附上了我的项目文件夹的图像,它可以帮助你理解我的问题,但它可以让我接受它,因为我的评论数量已经低于 10 。