Java Êý¾ÝÁ÷2(PipedInputStream,PipedOutputStream)
Java Êý¾ÝÁ÷2(PipedInputStream,PipedOutputStream...)
2007-08-18 17:30
×Ö½ÚÁ÷µÄ¸ß¼¶Ó¦ÓÃ
? ¹ÜµÀÁ÷
¹ÜµÀÓÃÀ´°ÑÒ»¸ö³ÌÐò¡¢Ï̺߳ʹúÂë¿éµÄÊä³öÁ¬½Óµ½ÁíÒ»¸ö³ÌÐò¡¢Ï̺߳ʹúÂë¿éµÄÊäÈë¡£java.ioÖÐÌṩÁËÀàPipedInputStreamºÍPipedOutputStream×÷Ϊ¹ÜµÀµÄÊäÈë/Êä³öÁ÷
¹ÜµÀÊäÈëÁ÷×÷Ϊһ¸öͨÐŹܵÀµÄ½ÓÊնˣ¬¹ÜµÀÊä³öÁ÷Ôò×÷Ϊ·¢ËͶˡ£¹ÜµÀÁ÷±ØÐëÊÇÊäÈëÊä³ö²¢Ó㬼´ÔÚʹÓùܵÀÇ°£¬Á½Õß±ØÐë½øÐÐÁ¬½Ó
¹ÜµÀÊäÈë/Êä³öÁ÷¿ÉÒÔÓÃÁ½ÖÖ·½Ê½½øÐÐÁ¬½Ó£º
– ÔÚ¹¹Ôì·½·¨ÖнøÐÐÁ¬½Ó
? PipedInputStream(PipedOutputStream pos);
? PipedOutputStream(PipedInputStream pis);
– ͨ¹ý¸÷×ÔµÄconnect()·½·¨Á¬½Ó
? ÔÚÀàPipedInputStreamÖУ¬connect(PipedOutputStream pos)£»
? ÔÚÀàPipedOutputStreamÖУ¬connect(PipedInputStream pis)£»
PipedStreamʾÀý£º
1.н¨¹¤³Ìpipedstreamtest,ÔÚ¹¤³ÌÖн¨Sender.java,Receiver.java,PipedStreamTest.javaÎļþ
2.¸÷JavaÎļþ´úÂëÈçÏ£º
2.1 Sender.java
package pipedstreamtest;
import java.io.*;
public class Sender extends Thread {
private PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getOutputStream(){
return out;
}
public Sender() {
}
public void run(){
String strInfo=new String("hello,receiver!");
try{
out.write(strInfo.getBytes());
out.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
2.2 Receiver.java
package pipedstreamtest;
import java.io.*;
public class Receiver extends Thread {
private PipedInputStrea
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
File.separatorChar ·µ»ØÒ»¸ö×Ö·û£¬±íʾµ±Ç°ÏµÍ³Ä¬ÈϵÄÎļþÃû·Ö¸ô·û£¬ÔÚWindowsÖÐΪ"\",unixÖÐΪ"/"¡£
File.separator ÓëÇ°ÕßÏàͬ£¬µ«½«·Ö¸ô·û×÷Ϊ×Ö·û´®ÀàÐÍ·µ»Ø¡£
pathSeparatorChar ·µ»ØÒ»¸ö×Ö·û£¬±íʾµ±Ç°ÏµÍ³Ä¬ÈϵÄ·¾¶Ãû·Ö¸ô·û£¬ÔÚWindowsÖÐΪ";",unixÖÐΪ":"¡£
File.pathSeparator ÓëÇ°ÕßÏàͬ£¬µ«½«·Ö¸ô·û×÷Ϊ×Ö· ......
¸ñʽ»¯Êä³öÊý×Ö
·Ò룺Cherami
email:cherami@163.net
ÔÎÄ£ºhttp://developer.java.sun.com/developer/TechTips/2000/tt0411.html
ÓÐʱÎÒÃÇÐèÒª¿ØÖÆÊä³öµÄÊý×ֵĸñʽ£¬ÈçºÎʹÓÃjavaµÄÀà¿â×öµ½Õâ¸öÄØ£¿
Ò²ÐíÄã²»¹ØÐĸñʽ£¬µ«ÊÇÄãÐèÒª¹ØÐÄÄãµÄ³ÌÐò¿ÉÒÔÔÚÈ«ÊÀ½çͨÓã¬Ï ......
Ò»¹²ÓÐÈý¸öÀࣺWriteFile ; ReadFile ; InsertDB ;
//WriteFile.java
//ÓÃÓÚ½«ÐÅϢдÈëÎı¾Îļþ
package org.mb.insertfromfile;
import java.io.*;
public class WriteFile{
private int count = 0 ;
public int getCount() {
return count;
}
public void setCount(int count) {
this.cou ......