1. 문자열에는 상호 변환이 통합되어 있습니다
문자열 a = string.valueof (2);
int i = integer.parseint (a);
2. 파일 끝에 컨텐츠를 추가하십시오
BufferedWriter out = null {out = new BufferedWriter ( ""filename, true);} catch (ioexception e) ror 프로세싱 코드}. ) {out.close ();}} 3. 현재 방법의 이름을 얻으십시오
String MethodName = thread.currentThread () [1] .getMethodName ();
4. 현재까지 문자열을 전송하십시오
java.util.date = java.text.dateformat.getDateInstance ();
또는:
simpledateformat 형식 = 새로운 simpledateformat ( "dd.mm.yyyy");
날짜 날짜 = format.parse (mystring);
5. JDBC 링크 Oracle을 사용하십시오
oraljdbctest {string driveclass = "oral.jdbc.driver.oderdriver"; String url = propproperty ( "db.url"); Con = DriverManager.getConnection (URL, 사용자 이름, 암호);} public void fetch ()는 sqlexception, ioexception {propectement ps = con.preparest ( "dual에서 sysdate selects = ps.executequry (); rs.next () {// 당신이하는 일을한다} rs.close (); );}} 6. Java Util.Date를 SQL.Date로 돌립니다
java.util.date utildate = new java.util.date ();
7. NIO를 사용하여 빠른 파일 사본을 수행하십시오
public static void filecopy (파일 in)는 ioexception {filechannel inca 채널 = getChannel (); , infhannel.size (), OutChannel); Windows의 큰 파일을 복사하는 데 어려움이 있습니다. 긴 크기 = infhannel.size (); infhannel.close ();} if (OutChannel! = null) {outChannel.close ();}}} 8. 사진의 축소판을 만듭니다
Private void CreateThumbnail (String filename, int tummwidth, int jumbheight, int quality, string untfilename), ioexception {// filename image = toolkit.getDefaultToolkit (filename); container (); mediaatracker.adimage. 너비와 높이의 썸네일 크기는 Double Thumbratio = (Double) intm imageWidth = int imageHeight = image.getHeight / (Double ImageWidth / (Double) imageWidth / (Double) imageHeight; if (Thumbratio <imageratio) {thumbheight = (int);} else {thumbwidth = (int) (jumbheigh * i mageratio) // 원본 이미지 Thumbnail 객체 및 // 새로운 크기의 Fly-Buffredimage ThumbImage = 새로운 Buffredimage (Thumbwidth, bufferedImage.type_int_int_rgb); value_interporation_bilinear); graphics2d.DrawImage (image, 0, 0, tumbwidth, null); JPEGENCODEPARAM PARAM = ENCODER.GetDefaultJPEGENCODEPARAM = MATH.MAX (품질, 100); ThumbImage); out.close ();}9. JSON 형식의 데이터를 만듭니다
아래 JAR 파일 : JSON-RPC-1.0.jar (75 KB) /http://t.cn/rz0bhua
org.json.jsonobject; 문자열 출력 = json.tostring ();
10. itext jar를 사용하여 pdf를 생성하십시오
java.io.fileoutputstream; .text.pdf.pdfwriter; public static void main (string [] args) {news ( "c : // t est.pdf"); getInstance (document.open); e.printstacktrace ();}}}}} 11. HTTP 프록시 설정
System.GetProperties (). proxyuseer ","someusername "); system.getProperties (). put ("http.proxypassword ","somepassword "); 12. 단일 인스턴스 싱글 톤 예제
공개 클래스 SIMPLESINGLETON {개인 정적 SimpleONGLETON SIGHTINSTANCE = 기본 생성자 표시 // ION. 13. 스크리닝 프로그램
java.ava.toolkit; 공개 캡처 스크린 (String Filename)은 {dimension screensize = getDefaultToolkit ()를 삭제합니다 , "png", 새 파일 (filename));} ... 14.리스트 파일 및 디렉토리
file dir = 새 파일 ( "directoryName"); <children.length; i ++) {// 파일 또는 디렉토리의 파일 이름을 얻는다. filename = children [i];} // restarnet f iles의 모든 목록이 시작된 파일을 반환하지 않습니다. '.' 파일 목록은 파일 개체 파일 [] files = dir.listfiles ()로 검색 될 수 있습니다 = dir.ListFiles (FileFilter); 15. zip 및 jar 파일을 만듭니다
Java.util.zip.*; : java zipit zip.zip file1 file3 file3 "); system.exit (-1);} 파일 zipfile = 새 파일 (args [0]); if (zipfile.exists ()) {system.err.println ("zip 파일 AlReam이 존재하고 다른 것을 시도하십시오 "); System.Exit (-2);} fileoutputStream fos = new FileoutStream (ZipFile); ZipoutPutStream ZOS = New UtputStream (fos); int bytesread; byte [] buffer = new Byte [1024] CRC32 CRC32 (int i = 1, n = args.length = arg); file .exists () {System.errr.println (스크리핑; 버퍼)! = 1) {crc.update (Buffer, 0, BytesRead);} bis.close (); intrict.setmethod. -1) {zos.write (buffer, 0, bytesread);} bis.close ();} zos.close ();}}16. XML 파일 분석/읽기
XML 파일
<? Mary </name> <grade> a </grade> <ge> 11 </age> </age> <tudent> <name> Simon </name> <grade> a </grade> <ege> 18 </ </age> </student> </stodent>
자바 코드
<font-family : arial; font-size; org.w3c.de org.w3c.dudelist {public void getallusername (string) {documentbuilderfactory.newinstance (); file.exist () {doc 닥터 = db.parse (file); doc.getDocumentedlement (); ()); Docele.getElements bytagname ( "학생"); && studerList.get.get.get () {int i = 0; i <windentList.getLength (); i ++. getNodeType () == node.element_node) {sysem.outln ( "==============="); nodelist = e.getElementsByTagName ( "name"); "이름 :" + nodelist.itmm (0). getchildnodes (0). 등급 "); system.out.println ("grade : " + nodelist.item (0) .getchildnodes () .item (0) .getNodevalue ()); nodElist = e.getElementsByTagName ("age "); System.out .println ( "age :" + nodelist.item (0) .getchildnodes (). item (). 항목 0) .getNodevalue ();}}} else {system.exit (1);}} catch (예외 e). {system.out.println (e);} public static void main (string [] args) {xmlparser er = new xmlparser (); 17. 배열을 맵으로 변환합니다
java.util.map; , "영국", "네덜란드", "암스테르담"}, "도쿄"}, { "파리"; .out.println ( "일본의 수도는" + countrycapitals.get ( "Japan"); System.out.println ( "프랑스의 자본" + count "trycapitals.get ("France ");}} 18. 메일 보내기
javax.mail.mail.internet.*; /호스트 smtp 주소 properties = "mail.smtp.host", "smtp.example.com"); .SetDeBug (Debug); .SetRcipients (recipienttype.to, addressto); msg.setsubject (주제);
19. HTTP 요청 프록시 데이터 전송 요청
import java.io.inputStreamReader; .cn/"); bufferedReader br = new bufferedReader ()) {system.out.println (strtemp);}} catch (예외) {ex.printstacktrace ();}}} 20. 배열의 크기를 변경하십시오
/** * 새로운 크기의 배열을 사용하고 이전 배열의 내용을 새 배열에 복사하십시오 AME 내용물 */Private Static Object Resizearray (int oldsize = java.lang.reflet.getlengtlengt h); java.lang.reflect.array.newinstance (electtype, int preservelenge) (oldsize, newsize); resizearray ()에 대한 테스트 루틴 (int [] a = {1,2,3}; ] = 5;위는이 기사의 모든 내용입니다.