-1

我有这个按钮,用于打开一个文本文件以便于调整。当我将文本文件放在同一目录中时它工作正常,但是当我尝试将它放在子目录中并将路径更改为“config/gameItems.txt”时它什么也没做,甚至没有告诉我它可以'找不到文件。有什么想法吗?

        JButton itemsButton = new JButton("Items");
            //Add action listener to button
            itemsButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
            {
                //Execute when button is pressed
                try {
                Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "config/gameItems.txt");
                } catch (Exception a) {
                System.out.println("File not found");
                }
            }
            });
4

2 回答 2

1

这是特定于 Windows 的代码,我认为问题在于使用文件分隔符“/”而不是“\”,尝试将代码更改为

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "config\\gameItems.txt");
于 2013-06-27T18:15:34.827 回答
1

由于您在 Windows 上执行此操作,请尝试以下操作:

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "config\\gameItems.txt");
于 2013-06-27T18:15:56.697 回答