開心生活站

位置:首頁 > IT科技 > 

java代碼

IT科技1.63W
品牌型號:聯想 YOGA 14c/系統版本:windows7

Java常用的代碼有

1、字符串整型互相轉換

String a = String.valueOf(2); //integer to numeric string   int i = Integer.parseInt(a); //numeric string to an int 

2、字符串轉日期

String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); 

3、得到當前方法的名字

String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); 

4、把 Java util.Date 轉成 sql.Date

java.util.Date utilDate = new java.util.Date();  java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); 

5、向文件末尾添加內容

BufferedWriter out = null;  try {    out = new BufferedWriter(new FileWriter(”filename”, true));    out.write(”aString”);  } catch (IOException e) {    // error processing code  } finally {    if (out != null) {      out.close();    }  } 

java代碼

標籤:java 代碼