java的IO流

文件 File
createNewFile()
delete()
exists() 文件存不存在
mkdir() 创建文件夹
mkdirs() 创建文件夹
list() 列出全部文件
isDirectory()
RandomAccessFile(File,"rw")


File.separator 
File.pathSeparator


文件流
InputStream 
--FileInputStream(f)
OutputStream
--FileOutputStream(f) (f,true)
Reader
--FileReader
Writer
--FileWriter

InputStreamReader
OutputStreamWriter

BufferedReader
BufferedWriter
BufferedInputStream
BufferedOutputStream

字节数组流
ByteArrayInputStream
ByteArrayOutputStream 

打印流
PrintStream

数据流
DataOutputStream
DataInputStream



合并流
SequenceInputStream 
主要用来将2个流合并在一起,
比如将两个txt的内容合并成另外的一个txt

InputStream input1 = new FileInputStream(file1);  
        InputStream input2 = new FileInputStream(file2);  
        OutputStream output = new FileOutputStream(file3);  
        // 合并流  
        SequenceInputStream sis = new SequenceInputStream(input1, input2);  
        int temp = 0;  
        while((temp = sis.read()) != -1){  
            output.write(temp);  
        }  

ZipOutputStream
压缩流
ZipInputStream
解压缩流
ZipFile



回退流
PushBackInputStream



对象的序列化:就是把对象变成二进制数据流的一种方法

类被序列号,必须实现 java.io.Serializable 接口


用于对象的序列化和反序列化(序列化存储在文件、数据库等等中)
ObjectOutputStream
ObjectInputStream









管道主要用于两个线程之间的通信
PipedOutputStream  管道输出流
PipedInputStream   管道输入流





















/**  
 * 验证管道流  
 * */ 
import java.io.*;  
 
/**  
 * 消息发送类  
 * */ 
class Send implements Runnable{  
    private PipedOutputStream out=null;  
    public Send() {  
        out=new PipedOutputStream();  
    }  
    public PipedOutputStream getOut(){  
        return this.out;  
    }  
    public void run(){  
        String message="hello , Rollen";  
        try{  
            out.write(message.getBytes());  
        }catch (Exception e) {  
            e.printStackTrace();  
        }try{  
            out.close();  
        }catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
}  
 
/**  
 * 接受消息类  
 * */ 
class Recive implements Runnable{  
    private PipedInputStream input=null;  
    public Recive(){  
        this.input=new PipedInputStream();  
    }  
    public PipedInputStream getInput(){  
        return this.input;  
    }  
    public void run(){  
        byte[] b=new byte[1000];  
        int len=0;  
        try{  
            len=this.input.read(b);  
        }catch (Exception e) {  
            e.printStackTrace();  
        }try{  
            input.close();  
        }catch (Exception e) {  
            e.printStackTrace();  
        }  
        System.out.println("接受的内容为 "+(new String(b,0,len)));  
    }  
}  
/**  
 * 测试类  
 * */ 
class hello{  
    public static void main(String[] args) throws IOException {  
        Send send=new Send();  
        Recive recive=new Recive();  
        try{  
//管道连接  
            send.getOut().connect(recive.getInput());  
        }catch (Exception e) {  
            e.printStackTrace();  
        }  
        new Thread(send).start();  
        new Thread(recive).start();  
    }  



2012 5 -- 11  
2012 12 -- 2013-5
2013 7 ---- 2014 3

你可能感兴趣的:(java的IO流)