很简单的问题! 怎样调用 public static void main(String[] args)里面的结果?
程序文件:
public class OrderNum {
static String getCurrentDate() {
java.util.Calendar now = java.util.Calendar.getInstance();
java.text.SimpleDateFormat yearAndMonth =new java.text.SimpleDateFormat( "yyyy-MM-dd ");
String retString = yearAndMonth.format(now.getTime());
return retString;
}
private static Object lock = new Object();
public OrderNum() {
}
public static void main(String[] args) throws Exception{
String logFile = "c:\\lastFile.txt ";
File lastFile = new File(logFile);
String strFileName ;
strFileName = " ";
BufferedWriter file = null;
BufferedReader input = null;
boolean firstUsed = false;
try {
synchronized (lock)
{
if (!lastFile.exists()) {
lastFile.createNewFile();
firstUsed = true;
}
if (firstUsed){
try{
file = new BufferedWriter(new FileWriter(logFile));
file.write(getCurrentDate() + "00000 ");
} catch (Exception e){
System.out.println(e);
} finally{
file.close();
}
}
firstUsed = false;
input = new BufferedReader(new FileReader(logFile));
String strNo=input.readLine();
strNo = strNo.substring(strNo.length()-5);
strNo= "00000 "+String.valueOf(Integer.parseInt(strNo)+1);
strNo=strNo.substring(strNo.length()-5);
//---------得到结果
strFileName = getCurrentDate()+strNo;
System.out.println(strFileName);
file = new BufferedWriter(new FileWriter(logFile));
file.write(strFileName);
}
} catch (Exception e) {
System.out.println(e);
}finally{
file.close();
input.close();
}
}
public class OrderNum {
static String getCurrentDate() {
java.util.Calendar now = java.util.Calendar.getInstance();
java.text.SimpleDateFormat yearAndMonth =new java.text.SimpleDateFormat( "yyyy-MM-dd ");
String retString = yearAndMonth.format(now.getTime());
return retString;
}
private static Object lock = new Object();
public OrderNum() {
}
public static void main(String[] args) throws Exception{