这是我的代码
static void filewrite() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
File f;
for (int i = 0; i <=1000000000; i++) {
f=new File("myfile" + i + ".txt");
if (!f.exists())
try {
f.createNewFile();
FileWriter fileWriter = new FileWriter(f);
fileWriter.write(dateFormat.format(date));
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("File Written");
}
}
正如您所看到的,我正在尝试编写包含日期的文件,但我只希望每次调用该函数时都创建一个文件。
感谢所有帮助!
答案 0 :(得分:0)
那是 int mHour = cc.get(Calendar.HOUR_OF_DAY);
int mMinute = cc.get(Calendar.MINUTE);
System.out.println("time_format"+String.format("%02d:%02d", mHour , mMinute ));
的用途。注意代码注释:
break
进一步阅读:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html