我有一个问题让这个工作.它包含一个由多条信息组成的字符串.但是,当我尝试将String写入文件以便跟踪程序随时间的变化时,我收到一个拒绝访问错误:
void writeToFile(String input) throws Exception{
File file = new File("C:\\WeatherExports\\export.txt");
if(!file.exists()){
file.createNewFile();
}
BufferedWriter inFile = new BufferedWriter(new FileWriter(file,true));
try{
inFile.append(input);
inFile.newLine();
} catch(Exception e){
e.printStackTrace();
}
inFile.close();
}
Run Code Online (Sandbox Code Playgroud)
STACKTRACE YEILDS:
java.io.FileNotFoundException: C:\WeatherExports\export.txt (Access is denied)
Run Code Online (Sandbox Code Playgroud)
完整Stacktrace:
java.io.FileNotFoundException: C:\WeatherExports\export.txt (Access is denied)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at org.weatheralert.InfoManipMethods.writeToFile(InfoManipMethods.java:58)
at org.weatheralert.Form.actionPerformed(Form.java:108)
at javax.swing.JTextField.fireActionPerformed(Unknown Source)
at javax.swing.JTextField.postActionEvent(Unknown Source)
at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source) …Run Code Online (Sandbox Code Playgroud) java filenotfoundexception access-denied bufferedwriter jsoup