好的,我正在编写一些applet作为java类的项目,我希望它从JTextArea
获取一个字符串,从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""写")"