当前位置: 代码迷 >> J2SE >> 很简单的有关问题! 怎样调用 public static void main(String[] args)里面的结果
  详细解决方案

很简单的有关问题! 怎样调用 public static void main(String[] args)里面的结果

热度:212   发布时间:2016-04-24 15:54:41.0
很简单的问题! 怎样调用 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{
  相关解决方案