源码
package com.io;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class FileOutputStreamTest {
public static void main(String[] args) throws Exception {
String path2 = "D:" + File.separator + "newfile.txt";
new File(path2).createNewFile();
String path = "D:" + File.separator + "fileoutputstreamtest.txt";
OutputStreamWirteFile(path);
}
public static void OutputStreamWirteFile(String path) {
try (OutputStream fos = new FileOutputStream(new File(path), true)) {
StringBuffer buf = new StringBuffer();
buf.append("Hello World!").append("\r\n");
buf.append("Hello Java!").append("\r\n");
buf.append("Hello Shao Yv!").append("\r\n");
buf.append("Hello Jing Tianming!").append("\r\n");
buf.append("Hello Gao Yue!").append("\r\n");
fos.write(buf.toString().getBytes());
fos.write(buf.toString().getBytes());
fos.write(buf.toString().getBytes());
} catch (Exception e) {
}
}
}