JAVA¹æÔò Öм¶Æª
±¾ÎĽéÉܵÄJAVA¹æÔòµÄ˵Ã÷·ÖΪ3¸öÖ÷Òª¼¶±ð£¬Öм¶ÊÇƽʱ¿ª·¢ÓõıȽ϶àµÄ¼¶±ð£¬ÔÚ½ñºó½«Â½Ðøд³öÆäËûµÄ¹æÔò¡£×ñÊØÁËÕâЩ¹æÔò¿ÉÒÔÌá¸ß³ÌÐòµÄЧÂÊ¡¢Ê¹´úÂëÓÖ¸üºÃµÄ¿É¶ÁÐԵȡ£
£¨1£© ÔÚfinally·½·¨Àï¹Øµôinput»òÕßoutput ×ÊÔ´
ÔÙ·½·¨ÌåÀïÃ涨ÒåÁËinput»òÕßoutputÁ÷µÄ»°£¬ÐèÒªÔÚfinallyÀïÃæ°ÑËü¹Øµô¡£
ÒÔÏÂÕ⼸ÖÖµ÷Óò»ÐèÒª×ñÊØÕâÌõ¹æÔò£¬ÒòΪcolse()·½·¨²»Æð×÷Ó㺣©
java.io.StringWriter java.io.ByteArrayOutputStream java.io.ByteArrayInputStream
Èç¹ûÔÙ·½·¨·µ»ØµÄʱºòûÓе÷ÓÃclose()·½·¨À´ÊÍ·Åinput()ºÍoutput()µÄ×ÊÔ´µÄ»°£¬»áµ¼ÖÂÒ»¸öϵͳ×ÊԴй©¡£¶øÇÒÔÚÈκÎÇé¿ö϶¼ÒªÈ·¶¨ÔÚ·µ»ØÈ«µ÷ÓÃÁËclose() ·½·¨£¬°üÀ¨³öÏÖÒì³£µÄʱºò¡£ËùÒÔÐèÒªÔÚfinally·½·¨ÀïÃæ¼ÓÈëÕâ¸ö·½·¨¡£ÕâÑù¾Í±£Ö¤ÁËÔÚÈκÎÇé¿ö϶¼»á¹Ø±Õ×ÊÔ´¡£
´íÎóʾÀý£º
public class CIO {
public void method (java.io.File f) {
java.io.FileInputStream fis = null;
try {
fis = new java.io.FileInputStream (f);
fis.read ();
fis.close ();
} catch (java.io.FileNotFoundException e1) {
System.out.println("File not found");
} catch (java.io.IOException e2) {
System.out.println("I/O Exception");
}
// Èç¹û³öÏÖÒì³££¬ÕâÀï¾Í²»Äܱ£Ö¤¹Ø±Õ×ÊÔ´¡£
}
}
ÐÞÕýºóµÄ´úÂ룺
public class CIOFixed {
public void method (java.io.File f) {
java.io.FileInputStream fis = null;
try {
&n
Ïà¹ØÎĵµ£º
×Ô¶¯×°ÏäºÍ×Ô¶¯²ðÏäÊÇjava5.0°æ±¾ÒýÈëµÄ£¬ÄÜ×Ô¶¯½«»ù±¾ÀàÐÍת»»Îª¶ÔÓ¦µÄ»ù±¾ÀàÐÍ°ü×°¶ÔÏó£¬ÄÇôÎÒÃDZȽÏÒ»ÏÂËûÃǵÄÐÔÄÜÇé¿ö¡£
package com.wmmad.test;
import junit.framework.TestCase;
/**
* @author madding.lip
*
* <pre>
* class: compare the autoboxing and unboxing and normal's performance
......
package homework01;
public class TestWhile {
public static double factorial(int n) //Çó½×³Ëº¯Êý
{
if(n==0) return 1;
else return n* factorial(n-1);
}
public static void main(String[] args) {
System.out.println(factorial(170));//test:ÄÜ´òÓ¡³öÀ´£ ......
1.±äÁ¿£º
¶ÔÓÚ»ù±¾ÀàÐ͵ÄÈ«¾Ö±äÁ¿£¬ÈôûÓгõʼ»¯£¬ÏµÍ³»á×Ô¶¯³õʼ»¯Îª¸ÃÀàÐ͵ijõʼֵ£»¶ø¶ÔÓÚ¾Ö²¿±äÁ¿£¬Ôò±ØÐëÏÔʾµÄ½øÐгõʼ»¯¡£
2.³£Á¿£º
final int M_Max=111;
final±íʾֻÄܸø±äÁ¿M_MAX¸³ÖµÒ»´Î£¬¸³ÖµÖ®ºó£¬M_MAXµÄÖµ¾Í²»¿ÉÒÔÖØи³Öµ¡£Ëù¸³µÄÖµ¿ÉÒÔÊÇÒ»¸ö±í´ïʽ£¬Ò²¿ÉÒÔÊÇÒ»¸ö¾ßÌåµÄÖµ¡£
3.Àà³£Á¿£º
static fina ......
Java¿ÉÒÔÖ±½Óµ÷ÓÃLinuxÃüÁÐÎʽÈçÏ£º
Runtime.getRuntime().exec(command)
¾ÙÀý£ºÔËÐÐls,topÃüÁî¿ÉÒÔÕâÑù£º
Runtime.getRuntime().exec("ls");
µ«ÊÇÕâÑùÖ´ÐÐʱûÓÐÈκÎÊä³ö£¬ÔÒò£º
µ÷ÓÃRuntime.exec·½·¨½«²úÉúÒ»¸ö±¾µØµÄ½ø³Ì,²¢·µ»ØÒ»¸öProcess×ÓÀàµÄʵÀý£¬
£¨×¢Ò⣺Runtim ......
ÕâÊÇÒ»¸öÓÃJAVA W3C DOM ½øÐÐXML²Ù×÷µÄÀý×Ó£¬°üº¬Á˲éѯ¡¢Ôö¼Ó¡¢Ð޸ġ¢É¾³ý¡¢±£´æµÄ»ù±¾²Ù×÷¡£½ÏÍêÕûµÄÃèÊöÁËÒ»¸öXMLµÄÕû¸ö²Ù×÷Á÷³Ì¡£ÊʺϸÕÈëÃÅJAVA XML²Ù×÷µÄÅóÓѲο¼ºÍѧϰ¡£
¼ÙÉèÓÐXMLÎļþ£ºtest1.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<name>¹þÀï²¨Ì ......