FileWriter使用netbeans无法正常工作

时间:2013-07-21 14:28:32

标签: netbeans filewriter

以下是使用netbeans在文件中打印当前时间的代码。

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{                                         
   // TODO add your handling code here:
   // l1.setText(randomInt+"Cleaned files");
   l1.setText("All viruses cleaned");
   String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
   FileWriter fileWriter = null;
   try {
       String content = "Hello! Java-Buddy :)";
       FileWriter f1=new FileWriter("filename.txt");
       f1.write(timeStamp);
       f1.close();
   } catch (IOException ex) {
       System.out.println(ex.getMessage());
       // Logger.getLogger(WriteStringToFile.class.getName()).log(Level.SEVERE, null, ex);
   }
}  

0 个答案:

没有答案