ºìÁªLinuxÃÅ»§
Linux°ïÖú

javaÖÐÊäÈëÊä³öµÄ×ÜÀ¨(³õѧ±Ø¿´)

·¢²¼Ê±¼ä:2006-09-06 00:45:59À´Ô´:ºìÁª×÷Õß:tongxiaokun
µÚ°ËÕ ÊäÈëÊä³öÁ÷
¡¾¿Îǰ˼¿¼¡¿
1. ×Ö½ÚÁ÷ºÍ×Ö·ûÁ÷µÄ»ùÀà¸÷ÊÇʲô£¿
2. ʲôÊǶÔÏóµÄ´®Ðл¯£¿¶ÔÏó´®Ðл¯µÄ×÷ÓÃÊÇʲô£¿
¡¾Ñ§Ï°Ä¿±ê¡¿
±¾½²Ö÷Òª½²ÊöÁËjavaÓïÑÔÖеÄÊäÈë/Êä³öµÄ´¦Àí£¬Í¨¹ý±¾½²µÄѧϰ£¬Í¬Ñ§ÃÇ¿ÉÒÔ±àд¸üΪÍêÉƵÄjava³ÌÐò¡£
¡¾Ñ§Ï°Ö¸ÄÏ¡¿
×ÐϸÔĶÁ±¾Õ¸÷֪ʶµãµÄÄÚÈÝ, Éî¿ÌÀí½â java ÓïÑÔÖÐÊäÈë/Êä³öÁ÷µÄ´¦Àí·½·¨,ÕÆÎÕ´¦ÀíÎÊÌâµÄ·½·¨,¶àÁ·Ï°,¶àÉÏ»ú¡£
¡¾ÄÑ ÖØ µã¡¿
 Óöµ½Êµ¼ÊÎÊÌâʱ£¬Òª¸ù¾ÝÐèÒªÕýȷʹÓø÷ÖÖÊäÈ룯Êä³öÁ÷£¬ÌرðÊǶÔÖÐÎÄʹÓÃÊʵ±µÄ×Ö·ûÊäÈëÁ÷¡£
 ÕýȷʹÓöÔÏó´®Ðл¯µÄ·½·¨¡£
 ´¦Àí×Ö·ûÁ÷ʱ£¬Æä¹¹Ôì·½·¨µÄ²ÎÊýÊÇÒ»¸ö×Ö½ÚÁ÷¡£
 ¶ÔÏó´®Ðл¯µÄ¸ÅÄî¡£
¡¾Öª ʶ µã¡¿
 I/O Á÷¸ÅÊö
 Îļþ´¦Àí
 ¹ýÂËÁ÷
 ×Ö·ûÁ÷µÄ´¦Àí
 ¶ÔÏóµÄ´®Ðл¯
 ÆäËü³£ÓõÄÁ÷
¡¾ÄÚ ÈÝ¡¿
µÚÒ»½Ú Êý¾ÝÁ÷µÄ»ù±¾¸ÅÄî
 Àí½âÊý¾ÝÁ÷
Á÷Ò»°ã·ÖΪÊäÈëÁ÷£¨Input Stream£©ºÍÊä³öÁ÷£¨Output Stream£©Á½À࣬µ«ÕâÖÖ»®·Ö²¢²»ÊǾø¶ÔµÄ¡£±ÈÈçÒ»¸öÎļþ£¬µ±ÏòÆäÖÐдÊý¾Ýʱ£¬Ëü¾ÍÊÇÒ»¸öÊä³öÁ÷£»µ±´ÓÆäÖжÁÈ¡Êý¾Ýʱ£¬Ëü¾ÍÊÇÒ»¸öÊäÈëÁ÷¡£µ±È»£¬¼üÅÌÖ»ÊÇÒ»¸öÊýÈËÁ÷£¬¶øÆÁÄ»ÔòÖ»ÊÇÒ»¸öÊä³öÁ÷¡£
 JavaµÄ±ê×¼Êý¾ÝÁ÷
±ê×¼ÊäÈëÊä³öÖ¸ÔÚ×Ö·û·½Ê½Ï£¨ÈçDOS£©£¬³ÌÐòÓëϵͳ½øÐн»»¥µÄ·½Ê½£¬·ÖΪÈýÖÖ£º
±ê×¼ÊäÈëstudin,¶ÔÏóÊǼüÅÌ¡£
±ê×¼Êä³östdout,¶ÔÏóÊÇÆÁÄ»¡£
±ê×¼´íÎóÊä³östderr,¶ÔÏóÒ²ÊÇÆÁÄ»¡£
Àý 8.1 ´Ó¼üÅÌÊäÈë×Ö·û¡£
±¾ÀýÓÃSystem.in.read(buffer)´Ó¼üÅÌÊäÈëÒ»ÐÐ×Ö·û£¬´æ´¢ÔÚ»º³åÇøbufferÖУ¬count±£´æʵ¼Ê¶ÁÈëµÄ×Ö½Ú¸öÊý£¬ÔÙÒÔÕûÊýºÍ×Ö·ûÁ½ÖÖ·½Ê½Êä³öbufferÖеÄÖµ¡£Read·½·¨ÔÚjava.io°üÖУ¬¶øÇÒÒªÅ׳öIOExceptionÒì³£¡£³ÌÐòÈçÏ£º
import java.io.*;
public class Input1
{
public static void main(String args[]) throws IOException
{
System.out.println("Input: ");
byte buffer[] = new byte[512]; //ÊäÈ뻺³åÇø
int count = System.in.read(buffer); //¶ÁÈ¡±ê×¼ÊäÈëÁ÷
System.out.println("Output: ");
for (int i=0;i{
System.out.print(" "+buffer[i]);
}
System.out.println();
for (int i=0;i{
System.out.print((char) buffer[i]);
}
System.out.println("count = "+ count); //bufferʵ¼Ê³¤¶È
}
}
³ÌÐòÖУ¬main·½·¨²ÉÓÃthrows×Ó¾äÅ׳öIOExceptionÒì³£½»ÓÉϵͳ´¦Àí¡£
 Java.io°üÖеÄÊý¾ÝÁ÷¼°ÎļþÀà
×Ö½ÚÁ÷£º
¡¡¡¡´ÓInputStreamºÍOutputStreamÅÉÉú³öÀ´µÄһϵÁÐÀà¡£ÕâÀàÁ÷ÒÔ×Ö½Ú(byte)Ϊ»ù±¾´¦Àíµ¥Î»¡£
 InputStream¡¢OutputStream
 ¡ó FileInputStream¡¢FileOutputStream
 ¡ó PipedInputStream¡¢PipedOutputStream
 ¡ó ByteArrayInputStream¡¢ByteArrayOutputStream
 ¡ó FilterInputStream¡¢FilterOutputStream
 ¡ó DataInputStream¡¢DataOutputStream
 ¡ó BufferedInputStream¡¢BufferedOutputStream
×Ö·ûÁ÷£º
¡¡¡¡´ÓReaderºÍWriterÅÉÉú³öµÄһϵÁÐÀ࣬ÕâÀàÁ÷ÒÔ16λµÄUnicodeÂë±íʾµÄ×Ö·ûΪ»ù±¾´¦Àíµ¥Î»
 Reader¡¢Writer
 ¡ó InputStreamReader¡¢OutputStreamWriter
 ¡ó FileReader¡¢FileWriter
 ¡ó CharArrayReader¡¢CharArrayWriter
 ¡ó PipedReader¡¢PipedWriter
 ¡ó FilterReader¡¢FilterWriter
 ¡ó BufferedReader¡¢BufferedWriter
 ¡ó StringReader¡¢StringWriter
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ