以下是使用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);
}
}