大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國(guó)咨詢/投訴熱線:400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁(yè) 學(xué)習(xí)攻略 Java學(xué)習(xí) 常用Java編程代碼大全

常用Java編程代碼大全

更新時(shí)間:2022-09-23 10:36:25 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽2685次

1. 字符串有整型的相互轉(zhuǎn)換

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

2. 向文件末尾添加內(nèi)容

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

3. 得到當(dāng)前方法的名字

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

4. 轉(zhuǎn)字符串到日期

java.util.Date = java.text.DateFormat.getDateInstance.parse(date String);
或者是:SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd" );
Date date = format.parse( myString );

5. 使用JDBC鏈接Oracle

public classOracleJdbcTest
{String driverClass = "oracle.jdbc.driver.OracleDriver";
Connection con;public void init(FileInputStream fs) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException
{Properties props = new Properties;
props.load(fs);String url = props.getProperty("db.url");
String userName = props.getProperty("db.user");
String password = props.getProperty("db.password");
Class.forName(driverClass);con=DriverManager.getConnection(url, userName, password);}public void fetch throws SQLException, IOException
{PreparedStatement ps = con.prepareStatement("select SYSDATE from dual");
ResultSet rs = ps.executeQuery;while (rs.next)
{// do the thing you do
}
rs.close;
ps.close;
}
publicstaticvoidmain(String[] args)
{
OracleJdbcTest test = new OracleJdbcTest;
test.init;
test.fetch;
}
}

6.列出文件和目錄

File dir = new File("directoryName");
String children = dir.list;
if (children == ) {
// Either dir does not exist or is not a directory
} else {
for (int i=0; i < children.length; i++) {
// Get filename of file or directory
String filename = children[i];
}
}
// It is also possible to filter the list of returned files.
// This example does not return any files that start with `.'.
FilenameFilter filter = new FilenameFilter {
public boolean accept(File dir, String name) {
return !name.startsWith(".");
}
};
children = dir.list(filter);
// The list of files can also be retrieved as File objects
File files = dir.listFiles;
// This filter only returns directories
FileFilter fileFilter = new FileFilter {
public boolean accept(File file) {
return file.isDirectory;
}
};
files = dir.listFiles(fileFilter);

7.解析/讀取XML 文件

<?xml version="1.0"?>
<students>
<student>
<name>John</name>
<grade>B</grade>
<age>12</age>
</student>
<student>
<name>Mary</name>
<grade>A</grade>
<age>11</age>
</student>
<student>
<name>Simon</name>
<grade>A</grade>
<age>18</age>
</student>
</students>

8. java分頁(yè)代碼實(shí)現(xiàn)

public class PageBean {
private int curPage; //當(dāng)前頁(yè)
private int pageCount; //總頁(yè)數(shù)
private int rowsCount; //總行數(shù)
private int pageSize=10; //每頁(yè)多少行
publicPageBean(int rows){
this.setRowsCount(rows);
if(this.rowsCount % this.pageSize == 0){
this.pageCount=this.rowsCount / this.pageSize;
}
else if(rows<this.pageSize){
this.pageCount=1;
}
else{
this.pageCount=this.rowsCount / this.pageSize +1;
}
}
publicintgetCurPage {
return curPage;
}
publicvoidsetCurPage(int curPage) {
this.curPage = curPage;

 

提交申請(qǐng)后,顧問(wèn)老師會(huì)電話與您溝通安排學(xué)習(xí)

  • 全國(guó)校區(qū) 2025-04-24 搶座中
  • 全國(guó)校區(qū) 2025-05-15 搶座中
  • 全國(guó)校區(qū) 2025-06-05 搶座中
  • 全國(guó)校區(qū) 2025-06-26 搶座中
免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 一区二区三区四区国产精品 | www.99爱 | 中文字幕日韩精品一区口 | 免费乱理伦片在线观看老妇 | 久久91精品国产一区二区 | 欧美一级毛片高清免费观看 | 久久国产麻豆 | 91日本在线精品高清观看 | 日本一级在线播放线观看视频 | 你懂得在线网站 | 国产日韩久久 | 最新中文字幕在线 | 日本爱情动作片网址 | 午夜色视频 | 神马不卡 | 亚洲国产成人精品一区二区三区 | 亚洲国产韩国一区二区 | 四虎影院永久免费 | 亚洲欧美精品久久 | 天天干天天射天天 | 狠狠亚洲 | 国产精品剧情原创麻豆国产 | 亚洲国产精品欧美日韩一区二区 | 夜夜躁日日躁狠狠 | 亚洲精品国产精品乱码不卞 | 中国国语毛片免费观看视频 | 不卡在线 | 四虎在线网址 | 操你妹影院 | 久久久久九九精品影院 | 我不卡老子影院午夜伦我不卡四虎 | 国产精品日本一区二区在线播放 | 国产成人小视频 | 嫩草社区 | 综合色桃花久久亚洲 | 国产真实伦视频在线观看 | 国产精品一区二区久久沈樵 | 天天射天天干天天插 | 国产伦精品一区二区三区免费观看 | 在线观看精品91老司机 | 91成人啪国产啪永久地址 |