public class Debug {
private FileConnection fconn;
private DataOutputStream dos;
private Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
public static Debug out = new Debug();
public Debug() {
openText();
}
private void openText() {
try {
fconn = (FileConnection) Connector.open("file:///e:/log.txt", Connector.READ_WRITE);
if (!fconn.exists()) {
fconn.create(); // create the file if it doesn't exist
} else {
fconn.delete();
fconn.create();
}
fconn.setWritable(true);
fconn.setReadable(true);
dos = fconn.openDataOutputStream();
} catch (Exception e) {
}
}
public void println(String str) {
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
StringBuffer s = new StringBuffer();
s.append(str + ";");
s.append("打印时间:" + hour + "点" + minute + "分" + ";");
try {
if (dos == null) {
if (fconn == null) {
openText();
} else {
dos = fconn.openDataOutputStream();
}
}
dos.flush();
dos.writeUTF(s.toString());
} catch (IOException ioe) {
dos = null;
}
}
}