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();
}
}