1. La cadena tiene una conversión mutua integrada
Cadena a = string.valueOf (2);
int i = Integer.ParseInt (a);
2. Agregue contenido al final del archivo
Bufferedwriter out = null; ) {out.close ();}} 3. Obtenga el nombre del método actual
String MethodName = Thread.CurrentThread ().
4. Transferencia de cadena hasta la fecha
java.util.date = java.text.dateformat.getDateInstance ().
O:
SimpleDateFormat Format = new SimpleDateFormat ("dd.mm.yyyy");
Fecha fecha = format.parse (myString);
5. Use el enlace JDBC Oracle
Clase pública oraljdbctest {string driveclass = "oral.jdbc.driver.oderdriver"; ; ; Mientras que rs.next ()) {// haz las cosas que haces} rs.close (); );}} 6. Gire a Java util.
java.util.date utildate = new java.util.date ();
7. Use NIO para realizar una copia de archivo rápido
Public static void fileCopy (archivo en, archivo out) lanza IOException {fileChannelinnel = new FileInputStream (in) .getChannel (); , infHannel.size (), outchannel); tamaño largo = infHannel.size (); infhannel.close ();} if (outchannel! = null) {outchannel.close ();}}} 8. Crea una miniatura de imágenes
Void Private CreateThumbnail (String FileName, int Thumbwidth, int ThingHeight, int Quality, String OutfileName) lanza International FoundException, IOException {// Cargue la imagen de FileName Image = Toolkit.getDefaultToolkit (). Contenedor ()); Determinar el tamaño de la miniatura desde el ancho y la altura Double Thumbratio = (Doble) Thumbwidth / (Double) Thumbheight; (Doble) ImageWidth / (Double) ImageHeight; Objeto de imagen en miniatura y // Escala al nuevo tamaño en la marcha BuffredImage Thumbimage = new BuffedImage (Thumbwidth, Thumbheight, BufferedImage.Type_int_rgb); value_interporation_bilinear); JPEGENCODEPARAM param = encoder.getDefaultJpegenCodeParam (Thumbimage); Thumbimage);9. Cree datos en formato JSON
Y el archivo jar a continuación: json-rpc-1.0.jar (75 kb) /http://t.cn/rz0bhua
Importar org.json.jsonObject; String output = json.ToString ();
10. Use Itext Jar para generar PDF
Import java.io.file; .Text.pdf.pdfwriter; getInstance (documento, archivo); E.PrintStackTrace ();}}}}}
11. Configuración de proxy HTTP
System.getProperties (). proxyUeer "," Someusername "); System.getProperties (). PUT (" http.proxypassword "," somePassword "); 12. Ejemplo de singleton de instancia única
Public Class SimplesingLeton {Private SimpleAngleton SingleInstance = new SimplesingLeton (); 13. Programa de detección
Importar java.awt.dimension; Public Void CaptureScreen (String FileName) lanza la excepción {Dimension Screensize = Toolkit.getDefaultToolkit (). , "PNG", nuevo archivo (nombre de archivo));} ... 14. Lista de archivo y directorio
Archivo dir = nuevo archivo ("DirectoryName"); <Children.length; con `. La lista de archivos aún se puede recuperar como archivo de objetos [] archivos = dir.listfiles (); = Dir.listfiles (fileFilter); 15. Crear archivos ZIP y JAR
Import java.util.zip.*; : java zipit zip.zip file1 file2 file3 "); system.exit (-1);} file zipfile = nuevo archivo (args [0]); if (zipfile.exists ()) {system.err.println (" ZIP File alream existe, intente otro "); System.Exit (-2);} fileOutputStream fos = new FileOutStream (ZipFile); ZipOutputStream Zos = new UtputStream (FOS); int bytesread; byte [] buffer = new byte [1024] ; CRC32 CRC = nuevo CRC32 (); ! Buffer)! ); -1) {Zos.Write (buffer, 0, bytesread);} bis.close ();} zo.close ();}}16. Analizar/leer el archivo XML
Archivo XML
<? XML Version = "1.0"?> <Students> <Enstude> <Name> John </name> <atrenal> b </grado> <ge> 12 </dge> </firection> <name> <name> Mary </name> <atrenal> a </at grado> <ge> 11 </dge> </firection> <student> <name> Simon </name> <atrenal> a </salte> <ege> 18 <// </dge> </stiet> </sterse>
Código Java
<span style = "Font-Family: Arial; Font-Size: 14px;"> Network de paquete. org.w3c.de; file.exist ()) {document doc = db.parse (archivo); ()); && studerlist.get.get.get. getNodeType () == node.element_node) {sysem.outln ("==== ==== =============="); Nodelist = E.GetElementsByTagName ("Nombre"); Grado "); system.out.println (" grado: " + nodelist.item (0) .getChildNodes () .Item (0) .getNodeValue ()); nodelist = e.getElementsBytaGName (" edad "); System.outT .println ("edad:" + nodelist.item (0) .getChildNodes (). item (). item 0) .getNodeValue ();}}} else {System.exit (1);}} Catch (Excepción e) {System.out.println (e);} public static void main (string [] args) {xmlParser er = new xmlParser (); 17. Convertir la matriz en mapa
Import java.util.map; , {"Reino Unido", "Londres"}, {"Países Bajos", "Amsterdam"}, {"Japón", "Tokio"}, {"marco", "París"} .out.println ("El capital de Japón es" + CountryCapitals.get ("Japón"); System.out.println ("El capital de Francia es" + Count "Trycapitals.get (" France "));}} 18. Enviar correo
Import javax.mail.*; /Establezca el host SMTP Properties Props = New Properties (); .setDebug (depuración); .SetRCipients (Message.RecipientType.to, dirección); escriba msg.setsubject (sujeto);
19. Solicitud HTTP que envía datos proxy
Import java.io.buffredReader; .cn/"); bufferedReader br = new BufferedReader ()) {System.out.println (strtemp);}} Catch (Exception Ex) {Ex.PrintStackTrace ();}} 20. Cambie el tamaño de la matriz
/** * Realización de una matriz con un nuevo tamaño y copia el contenido * de la matriz anterior a la matriz nueva. Con el contenido de AME. java.lang.reflect.array.newinstance (ElementType, Newsize); Return newaray;} // Prueba de rutina para RESIZARE (). ] = 5;
Lo anterior es todo el contenido de este artículo.