java程式碼
- IT科技
- 關注:1.53W次
品牌型號:聯想 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(); } }
- 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/dianzi/wxn5x2.html