易学笔记-0:Java语言总结/0.11 Java中输出的流表示(都是针对字节数组byte[ ]操作)
其他
2018-11-19 15:24:06
阅读次数: 0
- 针对缓存的:
- ByteArrayOutputStream
- StringBufferOutputStream
- 针对文件的:FileOutputStream
- 针对对象:ObjectOutputStream
- 针对线程的:PipedOutputStream
- 针对过滤器:FilterOutputtream
- DataOutputStream
- BufferedOutputStream
- 超级基类:OutputStream:public abstract class OutputStream implements Closeable, Flushable
- 写入:
- public abstract void write(int b) throws IOException;
- public void write(byte b[]) throws IOException
- public void write(byte b[], int off, int len) throws IOException
- 可替换:public void flush() throws IOException
- 可拷贝:public void close() throws IOException
- 字节数组输出流:ByteArrayOutputStream
- 数据结构
- protected byte buf[];
- protected int count;
- 方法
- public synchronized void write(int b)
- public synchronized void write(byte b[], int off, int len)
- public synchronized void writeTo(OutputStream out) throws IOException
- public synchronized byte toByteArray()[]
- public synchronized int size()
- 文件输出流:FileOutputStream
- public FileOutputStream(String name) throws FileNotFoundException
- public FileOutputStream(String name, boolean append)
- public FileOutputStream(File file) throws FileNotFoundException
- public FileOutputStream(File file, boolean append)
- public FileOutputStream(FileDescriptor fdObj)
- public void write(int b) throws IOException
- public void write(byte b[]) throws IOException
- public void write(byte b[], int off, int len) throws IOException
- public void close() throws IOException
- public final FileDescriptor getFD() throws IOException
- public FileChannel getChannel()
- 管道输出流:PipedOutputStream
- 过滤输出流:FilterOutputStream
- 数据成员
- protected OutputStream out;
- 方法:通过out调用相关的方法,构造方法就是接受外面的输入对象,比如:ByteArrayOutputStream 、FileOutputStream 、PipedOutputStream 等,实际上调用的就是传进来的对象
- DataOutPutStream:适应各种数据类型的输出
- 超级基类:DataOutput:接口用于将数据从任意 Java 基本类型转换为一系列字节,并将这些字节写入二进制流。同时还提供了一个将 String 转换成 UTF-8 修改版格式并写入所得到的系列字节的工具
- 写入整型:void write(int b) throws IOException;
- 写入字节数组:void write(byte b[]) throws IOException;
- 写入字节数组:void write(byte b[], int off, int len) throws IOException;
- 写入布尔:void writeBoolean(boolean v) throws IOException;
- 写入字节:void writeByte(int v) throws IOException;
- 写入短整型:void writeShort(int v) throws IOException;
- 写入字符:void writeChar(int v) throws IOException;
- 写入整型:void writeInt(int v) throws IOException;
- 写入长整型:void writeLong(long v) throws IOException;
- 写入浮点:void writeFloat(float v) throws IOException;
- 写入浮点:void writeDouble(double v) throws IOException;
- 写入字节流:void writeBytes(String s) throws IOException;
- 写入字符流:void writeChars(String s) throws IOException;
- 写入UTF:void writeUTF(String s) throws IOException;!
- DataOutputStream:实现 DataOutput 各个方法
- output的类型与input的类型要一致,也就是writeDouble与readDouble要一致,writeUTF与readUTF要一致
- 为了避免出现写入和读取类型问题,建议output采用统一的类型writeUTF,input时采用readUTF
转载自blog.csdn.net/u011830122/article/details/84180542