Java DataOutputStream类
定义
public DataOutputStream(OutputStream out)
参数
out:基础输出流。
方法
//将指定的字节写入管道输出流。 public void write(int b) public void write(byte[] b,int off,int len)
将指定的字节写入此字节数组输出流,此方法继承于OutputStream,可以参考OutputStream.write
//写入boolea,char,字节,utf8字符串等 public final void writeBoolean(boolean v) public final void writeByte(int v) public final void writeShort(int v) public final void writeChar(int v) public final void writeInt(int v) public final void writeLong(long v) public final void writeFloat(float v) public final void writeDouble(double v) public final void writeBytes(String s) public final void writeChars(String s) public final void writeUTF(String str) //写入数据输出流字节数 public final int size() //关闭流 public void close() public void flush()
例子
public static void main(String[] args) throws IOException { FileOutputStream in = new FileOutputStream("c\\51gjie.txt"); DataOutputStream out = new DataOutputStream( in ); String string = "欢迎来到www.51gjie.com"; out.writeBytes(string); out.writeChars(string); out.writeUTF(string); out.close(); System.out.println("写入成功!"); }
DataOutputStream允许应用程序以与机器无关方式将Java基本数据类型(boolean,byte,int,long,string等)写到底层输出流。
版权声明:本文为JAVASCHOOL原创文章,未经本站允许不得转载。