1. A string tem uma conversão mútua integrada
String a = string.valueof (2);
int i = Integer.parseint (a);
2. Adicione conteúdo ao final do arquivo
BufferWriter Out = NULL; ) {out.close ();}} 3. Obtenha o nome do método atual
String MethodName = Thread.CurrentThread ().
4. Transferir string até a data
java.util.date = java.text.dateFormat.getDateInstance ().
Ou:
SimpledateFormat format = new SimpleDateFormat ("dd.mm.yyyy");
Data data = format.parse (mystring);
5. Use o link JDBC Oracle
Classe pública oraljdbctest {string driveclass = "oral.jdbc.driver.oderdriver"; Url de String = Props.getProperty ("DB.url"); ; Enquanto Rs.Next ()) {// Faça as coisas que você faz} rs.close (); );}} 6. gire java util.date para sql.date
java.util.date ustildate = new java.util.date ();
7. Use o NIO para executar uma cópia rápida do arquivo
Public static void filecopy (arquivo in, file) lança ioexception {filechannel INCHAANNEL = new FileInputStream (in) .getChannel (); , infhannel.size (), outchannel); tamanho longo = infhannel.size (); infhannel.close ();} if (outchannel! = null) {outchannel.close ();}}} 8. Crie uma miniatura de fotos
Void privado CreateThumbNail (nome do arquivo de string, Int Whumbwidth, Int ThumbHeight, Int Quality, String OutfileName) lança a FoundException International, IoException {// carrega a imagem do nome do arquivo = Toolkit.getDefaultToolkit (). Container ()); Determine o tamanho da miniatura da largura e da altura dupla = (dupla) Thumbwidth / (duplo) (Duplo) ImageWidth / (Double) ImageHeight; Objeto de imagem em miniatura e // escala-o para o novo tamanho em BuffredImage Thumbimage = New BuffredImage (Whumbidth, ThumbHeight, BufferiMage.type_int_int_rgb); value_interporation_bilinear); JPEGENCODEPARAM PARAM = Encoder.getDefaultJPegencodeParam (Thumbimage); thumbimage);9. Crie dados no formato JSON
E o arquivo JAR abaixo: JSON-RPC-1.0.JAR (75 KB) /http://t.cn/rz0bhua
Importação de org.json.jsonObject; String Output = JSON.ToString ();
10. Use o jart para gerar pdf
Importar Java.io.File; .text.pdf.pdfwriter; getInstance (documento, arquivo); E.PrintStackTrace ();}}}}}
11. Configurações de proxy HTTP
System.getProperties (). proxyuseer "," algum nome "); system.getProperties (). put (" http.proxyPassword "," alguma palavra -palavra "); 12. Exemplo de única instância
Classe pública Simplesingleton {private static Simpleongleton singleInstance = new SimpleSingleton (); 13. Programa de triagem
Importar Java.awt.dimension; Public Void Capturescreen (String FileName) lança exceção {Dimension ScreenSize = Toolkit.getDefaultToolkit () , "Png", novo arquivo (nome do arquivo));} ... 14. Arquivo de lista e diretório
Arquivo Dir = NOVO FILE (DirectoryName "); <Children.Length; com `` Lista de arquivos ainda pode ser recuperada como arquivo de arquivo [] arquivos = DIR.LISTFILES (); = DIR.LISTFILES (FILEFILTER);
15. Crie arquivos zip e jar
Importar java.util.zip.*; : Arquivo Alream Existe, tente outro "); System.Exit (-2);} FileOutputStream fos = new FileOutStream (zipFile); ZipOutputStream zos = new UtputStream (fos); int bytesread; byte [] buffer = new Byte [1024] ; FILE! Buffer)! ); -1) {zos.write (buffer, 0, bytesread);} bis.close ();} zos.close ();}}16. Analisar/ler o arquivo XML
Arquivo XML
<? xml versão = "1.0"? Mary </name> <ver grau> a </ruda> <age> 11 </a Age> </cudent> <denty> <name> Simon </name> <rade> a </ruda> <ege> 18 </ </a Age> </ra -aluno> </fudents>
Código Java
<Span Style = "Fonte-Familia: Arial; Size da fonte: 14px; org.w3c.de; file.exist ()) {documento doc = db.parse (arquivo); ()); && studerlist.get.get.get. getNodetype () == Node.Element_Node) {sysem.outln ("==== ==== =============="); Nodelist = E.GetElementsByTagName ("Nome"); Grade "); System.out.println (" grau: " + nodelist.iTem (0) .getChildNodes () .Item (0) .getNodEvalue ()); nodelist = e.getElementsByTagName (" idade "); System.out.out .println ("idade:" + nodelist.item (0) .getChildNodes (). item (). Item 0) .getNodEvalue ();}}} else {System.exit (1);}} Catch (Exceção e) {System.out.println (e);} public static void main (string [] args) {xmlparser er = new xmlParser (); 17. Converta a matriz para mapear
Importar java.util.map; , {"Reino Unido", "Londres"}, {"Holanda", "Amsterdam"}, {"Japão", "Tóquio"}, {"Frame", "Paris"}; .out.println ("Capital do Japão é" + countrycapitals.get ("Japão"); System.out.println ("Capital da França é" + count "trycapitals.get (" França "));}}} 18. Envie o correio
Importar javax.mail.*; /Defina o endereço SMTP Propriedades do host = NOVA PROPRIETIVADO (); .SetDebug (Debug); .Setrcipients (Message.recipientType.to, endereço); Tipo msg.SetSubject (sujeito);
19. Solicitação HTTP enviando dados de proxy
Importar java.io.buffredReader; .cn/"); BufferredReader Br = new BufferReader ()) {System.out.println (strtemp);}} catch (Exceção ex) {ex.printStackTrace ();}}} 20. Altere o tamanho da matriz
/** * RealLocats Uma matriz com um novo tamanho e copia o conteúdo * da matriz antiga para a nova matriz. com o conteúdo do AME */RESIDENTES DE ESTÁTICOS PRIVADOS (Objeto OldArray, int Newsize) {int OldSize = java.lang.reflet.getlengtlengt h (OldArray); java.lang.reflect.array.NewInstance (ElementType, Newsize); Retorno Newaray;} // Rotina de teste para Reszearray () ] = 5;O acima é todo o conteúdo deste artigo. Espero que todos possam gostar.