java.io.FilePermission中的例外 - 从读取jar文件? [英] java.io.FilePermission exception - Read from jar file?
本文介绍了java.io.FilePermission中的例外 - 从读取jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有一个Java小程序起着我的本地文件系统的文件。当我嵌入小程序在网页中我得到一个io.FilePermission异常。据我所知,这一轮唯一的办法就是让我的小程序签名的,我不希望。
我将如何去阅读它自己的jar文件的文件?据我所知,这将是最好的方式。
感谢您的帮助球员。
我的继承人code
进口java.applet中的*。
进口java.awt中的*。
java.awt.event中导入*。公共类PlaySoundsApplet扩展小程序实现的ActionListener {
按钮播放,停止;
音频剪辑音频剪辑; 公共无效的init(){
玩=新按钮(播放中环);
加(打);
play.addActionListener(本);
停止=新按钮(停止);
加(停止);
stop.addActionListener(本);
音频剪辑= getAudioClip(得到codeBase的(),clip.wav); //异常这里试图从WWW根,而不是jar文件阅读 } 公共无效的actionPerformed(ActionEvent的AE){
按钮源=(按钮)ae.getSource();
如果(source.getLabel()==播放中环){
audioClip.play();
}
否则,如果(source.getLabel()==停止){
audioClip.stop();
}
}
}
更新code:
公共类PlaySoundsApplet扩展小程序实现的ActionListener {
按钮播放,停止;
音频剪辑音频剪辑; 公共无效的init(){
玩=新按钮(播放中环);
加(打);
play.addActionListener(本);
停止=新按钮(停止);
加(停止);
stop.addActionListener(本);
尝试{
的AudioInputStream的AudioInputStream = AudioSystem.getAudioInputStream(新文件(资源/ clip.wav));
剪辑音频剪辑= AudioSystem.getClip();
audioClip.open(的AudioInputStream);
}赶上(UnsupportedAudioFileException E1){的System.out.println(Unsoported错误);}
赶上(IOException异常E1){的System.out.println(IO错误);}赶上(LineUnavailableException E){的System.out.println(行不可用错误);}
} 公共无效的actionPerformed(ActionEvent的AE){
按钮源=(按钮)ae.getSource();
如果(source.getLabel()==播放中环){
audioClip.play();
}
否则,如果(source.getLabel()==停止){
audioClip.stop();
}
}
}
解决方案
尝试
URL网址= getDocumentBase();音频剪辑音频剪辑= getAudioClip(URL,音乐/ JButton.wav)
项目内在张力结构
Hi I have a Java Applet which plays a file of my local file system. When I embed the Applet in a web page I get a io.FilePermission Exception. I understand that the only way round this is to get my Applet signed which I don't wish to.
How would I go about read the file from it's own jar file?, As I understand this will be the best way.
Thanks for any help guys.
Heres my code
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class PlaySoundsApplet extends Applet implements ActionListener{
Button play,stop;
AudioClip audioClip;
public void init(){
play = new Button(" Play in Loop ");
add(play);
play.addActionListener(this);
stop = new Button(" Stop ");
add(stop);
stop.addActionListener(this);
audioClip = getAudioClip(getCodeBase(), "clip.wav"); //Exception here trying to read from the www root instead of jar file
}
public void actionPerformed(ActionEvent ae){
Button source = (Button)ae.getSource();
if (source.getLabel() == " Play in Loop "){
audioClip.play();
}
else if(source.getLabel() == " Stop "){
audioClip.stop();
}
}
}
Updated code:
public class PlaySoundsApplet extends Applet implements ActionListener{
Button play,stop;
AudioClip audioClip;
public void init(){
play = new Button(" Play in Loop ");
add(play);
play.addActionListener(this);
stop = new Button(" Stop ");
add(stop);
stop.addActionListener(this);
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("resources/clip.wav"));
Clip audioClip = AudioSystem.getClip();
audioClip.open(audioInputStream);
} catch (UnsupportedAudioFileException e1) {System.out.println("Unsoported Error");}
catch (IOException e1) {System.out.println("IO Error");} catch (LineUnavailableException e) {System.out.println("Line unavailable Error");}
}
public void actionPerformed(ActionEvent ae){
Button source = (Button)ae.getSource();
if (source.getLabel() == " Play in Loop "){
audioClip.play();
}
else if(source.getLabel() == " Stop "){
audioClip.stop();
}
}
}
解决方案
Try
URL url = getDocumentBase();
AudioClip audioClip = getAudioClip(url, "music/JButton.wav")
Project sturcture
这篇关于java.io.FilePermission中的例外 - 从读取jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文