【问题标题】:java war file throws FileNotFoundException in jar filejava war文件在jar文件中抛出FileNotFoundException
【发布时间】:2020-02-04 19:15:08
【问题描述】:

我有一个带有战争文件声音的程序。当我在 Eclipse 中运行程序时,声音播放得很好,但在 jar 文件中,我得到了 FileNotFoundException。这就是我添加战争文件的方式:

public class MainClass implements Serializable{

    private static final long serialVersionUID = 1L;
    public static Library library;
    
    public static void main(String[] args)
    {
        try {
            loading();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        
        if(library == null) {
            library = Library.getInstance();
        }
        
        try
        {
            FileInputStream button4 = new FileInputStream("sound/welcome.wav");
            AudioStream b4 = new AudioStream(button4);
            AudioPlayer.player.start(b4);
        }
        catch(FileNotFoundException e)
        {
            JOptionPane.showMessageDialog(null,"File not found");
        }
        catch(IOException eio)
        {
            JOptionPane.showMessageDialog(null,"Sound Problems");
        }
        Login login = new Login();
        login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        login.setVisible(true);
        login.setSize(600, 400);
    }
}

war 文件与我的项目位于同一文件夹中。我需要以不同的方式添加文件吗? 以下是 war 文件在项目中的位置:

【问题讨论】:

标签: java file user-interface audio war


【解决方案1】:

战争上下文中的“文件路径”与您的 IDE 中的路径不同,并且以这种方式使用 FileInputStream 不起作用。

有关如何从 war/servlet 上下文中加载资源的提示,请参阅 File path to resource in our war/WEB-INF folder?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多