好的,所以我正在编写一些小程序作为 java 类的项目,我希望它从 a 中获取一个字符串,从 aJTextArea
中获取另一个字符串,JTextField
从单选按钮中获取一个选项,当用户点击“提交”时,它会写入所有将信息写入 txt 文件,如下所示:
Quote Message - Name Message - Radio option
现在,我已经将其打印到可以完全按照上述方式打印出来的位置,但我无法将其打印到 txt 文件中。这是我目前拥有的:
private class SubmitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String quoteString = quoteText.getText();
String nameString = nameText.getText();
String color = null;
if(redButton.isSelected())
color = "red";
else if(blueButton.isSelected())
color = "blue";
else if(greenButton.isSelected())
color = "green";
System.out.println(quoteString + "-" + nameString + "-" + color); // For testing
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("index.txt"), "utf-8"))) {
writer.write(quoteString + "-" + nameString + "-" + color);
}
catch (IOException ex){
ex.printStackTrace();
}
}
}
但是当我尝试执行它时,我得到
“线程“AWT-EventQueue-1”中的异常 java.security.AccessControlException:访问被拒绝(“java.io.FilePermission”“index.txt”“write”)”