java IO²Ù×÷ (¶Áд¡¢×·¼Ó¡¢É¾³ý¡¢Òƶ¯¡¢¸´ÖƵÈ)
Ò»¡¢¶àÖÖ·½Ê½¶ÁÎļþÄÚÈÝ¡£
1¡¢°´×Ö½Ú¶ÁÈ¡ÎļþÄÚÈÝ
2¡¢°´×Ö·û¶ÁÈ¡ÎļþÄÚÈÝ
3¡¢°´ÐжÁÈ¡ÎļþÄÚÈÝ
4¡¢Ëæ»ú¶ÁÈ¡ÎļþÄÚÈÝ
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
public class ReadfromFile {
/**
* ÒÔ×Ö½ÚΪµ¥Î»¶ÁÈ¡Îļþ£¬³£ÓÃÓÚ¶Á¶þ½øÖÆÎļþ£¬ÈçͼƬ¡¢ÉùÒô¡¢Ó°ÏñµÈÎļþ¡£
* @param fileName ÎļþµÄÃû
*/
public static void readFileByBytes(String fileName){
File file = new File(fileName);
InputStream in = null;
try {
System.out.println("ÒÔ×Ö½ÚΪµ¥Î»¶ÁÈ¡ÎļþÄÚÈÝ£¬Ò»´Î¶ÁÒ»¸ö×Ö½Ú£º");
// Ò»´Î¶ÁÒ»¸ö×Ö½Ú
in = new FileInputStream(file);
int tempbyte;
while((tempbyte=in.read()) != -1){
System.out.write(tempbyte);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
try {
System.out.println("ÒÔ×Ö½ÚΪµ¥Î»¶ÁÈ¡ÎļþÄÚÈÝ£¬Ò»´Î¶Á¶à¸ö×Ö½Ú£º");
//Ò»´Î¶Á¶à¸ö×Ö½Ú
byte[] tempbytes = new byte[100];
int byteread = 0;
in = new FileInputStream(fileName);
ReadfromFile.showAvailableBytes(in);
//¶ÁÈë¶à¸ö×Ö½Úµ½×Ö½ÚÊý×éÖУ¬bytereadΪһ´Î¶ÁÈëµÄ×Ö½ÚÊý
while ((byteread = in.read(tempbytes)) != -1){
System.out.write(tempbytes, 0, byteread);
}
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (in != nul
Ïà¹ØÎĵµ£º
synchronized£º ͬ²½µÄ
synchronizedÔÚ²Ù×÷ÉÏÓÐÁ½ÖÖÓ°Ïì¶ÔÏóµÄÇé¿ö£º
1) ÔÚij¸ö¶ÔÏóʵÀýÄÚ£¬synchronized method(){}¿ÉÒÔ·ÀÖ¹¶à¸öÏß³Ìͬʱ·ÃÎÊÕâ¸ö¶ÔÏóµÄsynchronized·½·¨£¨Èç¹ûÒ»¸ö¶ÔÏóÓжà¸ösynchronized·½·¨£¬Ö»ÒªÒ»¸öÏ̷߳ÃÎÊÁËÆäÖеÄÒ»¸ösynchronized·½·¨£¬ÆäËüÏ̲߳»ÄÜͬʱ·ÃÎÊÕâ¸ö¶ÔÏóÖÐÈκÎÒ»¸ösynchronized·½·¨£ ......
/**
* Õâ¶Î³ÌÐò²¢²»ÄÑ£¬Ó¦¸ÃºÜºÃ¿´¶®£¬ÎҰѹý³Ì´óÖ½²Ò»Ï£¬Ê×ÏÈÄãµÄÄÔ×ÓÀïÏȸ¡ÏÖÒ»¸öÊý×éºÍÈý¸öÖ¸Õ룬
* µÚÒ»¸öÖ¸Õë³ÆΪpÖ¸Õ룬ÔÚÕû¸ö¹ý³Ì½áÊø֮ǰËüÀÎÀεÄÖ¸ÏòµÚÒ»¸öÊý£¬µÚ¶þ¸öÖ¸ÕëºÍµÚÈý¸öÖ¸Õë·Ö±ðΪloÖ¸ÕëºÍhiÖ¸Õ룬
* ·Ö±ðÖ¸Ïò×î×ó±ßµÄÖµºÍ×îÓұߵÄÖµ¡£loÖ¸ÕëºÍhiÖ¸Õë´ÓÁ½±ßͬ ......
½ñÌìÓöµ½Ò»¸öÒªÉú³ÉÒ»¸öÏÂÀÁбí¿òµÄÎÊÌ⣬ÎÒµÄÏë·¨ÊÇ£º½«Êý¾Ý¿âÄÚµÄËùÓÐÊý¾Ý¶¼´æ´¢µ½Ò»¸öListÀïÃ棬ÔÙÔÚǰ̨±éÀúÕû¸ölist¡£
Ö´ÐÐЧ¹ûͼ£º
Ë®¹û
→Æ»¹û
→→Æ»¹ûϵÁÐ1
→→Æ»¹ûϵÁÐ2
→→Æ»¹ûϵÁÐ3
→→Æ»¹ûϵÁÐ4
→Àæ
→ÌÒ×Ó
ѧϰÓÃÆ·
→±Ê
→→Ǧ±Ê ......
1.°Ë½øÖÆתÒåÐòÁУº\ + 1µ½3λ5Êý×Ö£»·¶Î§'\000'~'\377'
\0£º¿Õ×Ö·û
2.UnicodeתÒå×Ö·û£º\u + ËĸöÊ®Áù½øÖÆÊý×Ö£»0~65535
\u0000£º¿Õ×Ö·û
3.ÌØÊâ×Ö·û£º¾Í3¸ö
\"£ºË«ÒýºÅ
\'£ºµ¥ÒýºÅ
&nbs ......
/*
* @(#)ObjectPoolManager.java 1.00 2005-5-1
*
* Copyright 2005 BeanSoft Studio. All rights reserved.
* PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package  ......