021.15 IO流 其他流

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());
}
上一篇:hql 函数大全


下一篇:Eclipse 扩展activiti-desinger 安装