欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

021.15 IO流 其他流

程序员文章站 2023-04-07 09:39:19
IO包中的其他类操作基本数据类型:DataInputStream与DataOutputStream操作字节数组:ByteArrayInputStream与ByteArrayOutputStream操作字符数组:CharArrayReader与CharArrayWriter操作字符串:StringRe ......

 

io包中的其他类
操作基本数据类型:datainputstream与dataoutputstream
操作字节数组:bytearrayinputstream与bytearrayoutputstream
操作字符数组:chararrayreader与chararraywriter
操作字符串:stringreader与stringwriter

 

####datainputstream与dataoutputstream
public static void main(string[] args) throws ioexception
{
    writefile();
    readfile();
}


private static void writefile() throws ioexception
{
    fileoutputstream fos = new fileoutputstream("myfile\\data.txt");
    dataoutputstream dos = new dataoutputstream(fos);
    
    dos.writeboolean(true);
    
    dos.close();
}

private static void readfile() throws ioexception
{
    fileinputstream fis = new fileinputstream("myfile\\data.txt");
    datainputstream dis = new datainputstream(fis);
    
    boolean b;
    b = dis.readboolean();
    system.out.println(b);
    
    dis.close();
}


#####bytearrayinputstream与bytearrayoutputstream
public static void main(string[] args)
{
    bytearrayinputstream bis = new bytearrayinputstream("abcdef".getbytes());
    bytearrayoutputstream bos = new bytearrayoutputstream();
    
    int b;
    while((b = bis.read())!=-1){
        bos.write(b);
    }
    system.out.println(bos.tostring());
}