JAVA把得到日期写进文件里,晕~请教师傅!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/01 18:59:28
package pac;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.*;

public class TestWrite {

/**
* @param args
*/
public static void main(String[] args)
{
Calendar cl=Calendar.getInstance();
String s=(cl.get(Calendar.YEAR)+"年"+
cl.get(Calendar.MONTH)+"月"+
cl.get(Calendar.DAY_OF_MONTH)+"日 "+
cl.get(Calendar.HOUR_OF_DAY)+"点"+
cl.get(Calendar.MINUTE)+"分");

try {
FileOutputStream fos=new FileOutputStream("e:\\Time.txt");
int d=0;
while(d!=-1)
{
fos.write(xxxxxxx);-----这里参数不知道怎么填,请教师傅该如何写???
d++;
}

fos.close();

} catch (FileNotFoundException e)

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;

public class TestWrite {

public static void main(String[] args) {
Calendar cl = Calendar.getInstance();
String s = (cl.get(Calendar.YEAR) + "年" + cl.get(Calendar.MONTH) + "月"
+ cl.get(Calendar.DAY_OF_MONTH) + "日 "
+ cl.get(Calendar.HOUR_OF_DAY) + "点" + cl.get(Calendar.MINUTE) + "分");
FileOutputStream fos = null;
try {
fos = new FileOutputStream("d:\\Time.txt");
byte ss[] = s.getBytes();// 要先定义一个byte数组
fos.write(ss);// 你可以查看api发现这个只能写入数组
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();

} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
<