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
Ïà¹ØÎĵµ£º
Java Àà·¾¶
Java Àà·¾¶¸æËß java ½âÊÍÆ÷ºÍ javac ±àÒëÆ÷È¥ÄÄÀïÕÒËüÃÇÒªÖ´Ðлòµ¼ÈëµÄÀà¡£ÀࣨÄú¿ÉÄÜ×¢Òâµ½µÄÄÇЩ *.class Îļþ£©¿ÉÒÔ´æ´¢ÔÚĿ¼»ò jar ÎļþÖУ¬»òÕß´æ´¢ÔÚÁ½ÕßµÄ×éºÏÖУ¬µ«ÊÇÖ»ÓÐÔÚËüÃÇλÓÚÀà·¾¶ÖеÄij¸öµØ·½Ê±£¬Java ±àÒëÆ÷»ò½âÊÍÆ÷²Å¿ÉÒÔÕÒµ½ËüÃÇ¡£
ÔÚ Windows ÖУ¬Àà·¾¶ÖеĶà¸öÏîÊÇÓ÷ֺŷָô£¨ ;£ ......
Compositeģʽ(×éºÏ)
JavaÉîÈëµ½Ò»¶¨³Ì¶È,¾Í²»¿É±ÜÃâµÄÅöµ½Éè¼ÆģʽÕâÒ»¸ÅÄî,Á˽âÉè¼Æģʽ,½«Ê¹×Ô¼º¶ÔjavaÖеĽӿڻò³éÏóÀàÓ¦ÓÃÓиüÉîµÄÀí½â.Éè¼ÆģʽÔÚjavaµÄÖÐÐÍϵͳÖÐÓ¦Óù㷺,×ñÑÒ»¶¨µÄ±à³Ìģʽ,²ÅÄÜʹ×Ô¼ºµÄ´úÂë±ãÓÚÀí½â,Ò×ÓÚ½»Á÷,Composite(×éºÏģʽ)ģʽÊDZȽϳ£ÓõÄÒ»¸öģʽ.
Composi ......
¡¡¡¡6.1 »ù±¾Êý¾ÝÀàÐÍ
¡¡¡¡´«ÊÚÐÂÖª
¡¡¡¡ÔÚJavaÓïÑÔÖУ¬Êý¾ÝÀàÐÍ¿ÉÒÔ·ÖΪÁ½´óÀࣺ
¡¡¡¡1£©»ù±¾ÀàÐÍ£»
¡¡¡¡2£©À©Õ¹ÀàÐÍ¡£
¡¡¡¡ÔÚ±¾Ð¡½ÚÖУ¬ÎÒÃǾÍÒ»ÆðÀ´Ñ§Ï°Ò»ÏÂJavaÓïÑԵĻù±¾Êý¾ÝÀàÐÍ¡£Ëü°üÀ¨£ºboolean¡¢char¡¢byte¡¢int¡¢short¡¢long¡¢float¡¢double°ËÖÖ£º
¡¡¡¡ÀàÐÍ ÃèÊö È¡Öµ·¶Î§
¡¡¡¡Boolean ²¼¶ûÐÍ Ö»ÓÐÁ½¸öÖµt ......
synchronized£º ͬ²½µÄ
synchronizedÔÚ²Ù×÷ÉÏÓÐÁ½ÖÖÓ°Ïì¶ÔÏóµÄÇé¿ö£º
1) ÔÚij¸ö¶ÔÏóʵÀýÄÚ£¬synchronized method(){}¿ÉÒÔ·ÀÖ¹¶à¸öÏß³Ìͬʱ·ÃÎÊÕâ¸ö¶ÔÏóµÄsynchronized·½·¨£¨Èç¹ûÒ»¸ö¶ÔÏóÓжà¸ösynchronized·½·¨£¬Ö»ÒªÒ»¸öÏ̷߳ÃÎÊÁËÆäÖеÄÒ»¸ösynchronized·½·¨£¬ÆäËüÏ̲߳»ÄÜͬʱ·ÃÎÊÕâ¸ö¶ÔÏóÖÐÈκÎÒ»¸ösynchronized·½·¨£ ......
(1)Õ»
package ChapterOne;
public class Stack {
//Õ»Êý×é
long stackArr[];
//Õ»µÄ´óС
int maxSize;
//Õ»µÄ¶¥²¿
int top;
//³õʼ»¯Ò»¸ö´óСΪsizeµÄÕ»
public Stack(int size){
maxSize = size;
stackArr = new long[size];
top = -1;
}
//³öÕ»²Ù×÷
public long pop(){
return sta ......