电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

非常有用的Java程序片段VIP免费

非常有用的Java程序片段_第1页
1/22
非常有用的Java程序片段_第2页
2/22
非常有用的Java程序片段_第3页
3/22
非常有用的Java程序片段1.字符串有整型的相互转换Java代码Stringa=String.valueOf(2);//integertonumericstringinti=Integer.parseInt(a);//numericstringtoanint2.向文件末尾添加内容Java代码BufferedWriterout=null;try{out=newBufferedWriter(newFileWriter(”filename”,true));out.write(”aString”);}catch(IOExceptione){//errorprocessingcode}finally{if(out!=null){out.close();}}3.得到当前方法的名字Java代码StringmethodName=Thread.currentThread().getStackTrace()[1].getMethodName();4.转字符串到日期Java代码java.util.Date=java.text.DateFormat.getDateInstance().parse(dateString);或者是:SimpleDateFormatformat=newSimpleDateFormat("dd.MM.yyyy");Datedate=format.parse(myString);5.使用JDBC链接OracleJava代码publicclassOracleJdbcTest{StringdriverClass="oracle.jdbc.driver.OracleDriver";Connectioncon;publicvoidinit(FileInputStreamfs)throwsClassNotFoundException,SQLException,FileNotFoundException,IOException{Propertiesprops=newProperties();props.load(fs);Stringurl=props.getProperty("db.url");StringuserName=props.getProperty("db.user");Stringpassword=props.getProperty("db.password");Class.forName(driverClass);con=DriverManager.getConnection(url,userName,password);}publicvoidfetch()throwsSQLException,IOException{PreparedStatementps=con.prepareStatement("selectSYSDATEfromdual");ResultSetrs=ps.executeQuery();while(rs.next()){//dothethingyoudo}rs.close();ps.close();}publicstaticvoidmain(String[]args){OracleJdbcTesttest=newOracleJdbcTest();test.init();test.fetch();}}6.把Javautil.Date转成sql.DateJava代码java.util.DateutilDate=newjava.util.Date();java.sql.DatesqlDate=newjava.sql.Date(utilDate.getTime());7.使用NIO进行快速的文件拷贝Java代码publicstaticvoidfileCopy(Filein,Fileout)throwsIOException{FileChannelinChannel=newFileInputStream(in).getChannel();FileChanneloutChannel=newFileOutputStream(out).getChannel();try{//inChannel.transferTo(0,inChannel.size(),outChannel);//original--apparentlyhastroublecopyinglargefilesonWindows//magicnumberforWindows,64Mb-32Kb)intmaxCount=(64*1024*1024)-(32*1024);longsize=inChannel.size();longposition=0;while(position

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

非常有用的Java程序片段

确认删除?
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群