JavaSE I/O 输出字节流 OutputStream

来源:互联网 发布:家庭装修网络布线方案 编辑:程序博客网 时间:2024/06/07 01:35


package com.javaIO.file;import java.io.FileOutputStream;import java.io.OutputStream;public class FileOutputStreamTest {public static void main(String[] args) throws Exception {OutputStream os = new FileOutputStream("e:/newOut.txt");String str = "asdfghjhklmnbv i'm already been there before.";byte[] buffer = str.getBytes();os.write(buffer);os.close();}}


实例二:

package com.javaIO.file;import java.io.BufferedOutputStream;import java.io.DataOutputStream;import java.io.FileOutputStream;import java.io.OutputStream;public class FileOutputStreamTest {public static void main(String[] args) throws Exception {OutputStream os = new FileOutputStream("e:/newOut3.txt");DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(os));  // 装饰模式 ,给dos对象附加功能。String str = "hey man.";byte[] buffer = str.getBytes();dos.write(buffer);  //写入到流中dos.close();}}



0 0
原创粉丝点击