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

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學習攻略 Java學習 常用Java編程代碼大全

常用Java編程代碼大全

更新時間:2022-09-23 10:36:25 來源:動力節點 瀏覽2801次

1. 字符串有整型的相互轉換

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

2. 向文件末尾添加內容

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. 得到當前方法的名字

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

4. 轉字符串到日期

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分頁代碼實現

public class PageBean {
private int curPage; //當前頁
private int pageCount; //總頁數
private int rowsCount; //總行數
private int pageSize=10; //每頁多少行
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;

 

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 九九爱精品视频 | 精品99牛牛视频 | 中文欧美一级强 | 国产在线欧美日韩一区二区 | 91在线 | 欧美:| 免费国产一级特黄aa大片在线 | 国产精品揄拍100视频 | 免费在线a| 伊人久热这里只精品视频 | 51啪影院| 最新国产麻豆精品 | 精品视频在线一区 | 国产亚洲欧美精品久久久 | 这里精品 | 四虎影视精品永久免费网站 | 射久久| 国产成年网站v片在线观看 国产成人 免费观看 | 久久福利资源国产精品999 | 中国免费一级毛片 | 日韩在线视频一区二区三区 | 国产特级毛片aaaaaa | 青草视频网站 | 国产精品久久毛片蜜月 | 亚洲一区二区三区高清不卡 | 亚洲www色 | 这里只有精品在线 | 奇米影视77 | 国产精品久久成人影院 | 日韩你懂得 | 7777奇米影视 | 欧美一级特黄真人毛片 | 99精品国产成人a∨免费看 | 看免费一级片 | 麻豆久久精品 | 久久嫩草影院免费看夜色 | 97国产成人精品免费视频 | 高清国产美女在线观看 | 一区二区3区免费视频 | 九九视频高清视频免费观看 | 亚洲精品久久久久午夜 | 久久午夜夜伦伦鲁鲁片 |