io之FileOutputStream
程序员文章站
2022-05-28 16:50:59
...
package com.laien.io; import java.io.FileOutputStream; import java.io.OutputStream; /** * 从程序中往硬盘写数据,谓之output * * @author Administrator * */ public class OutputStreamTest { public static void main(String[] args) throws Exception { //如果已有文件,覆盖原有内容,否则,新建文件并写下内容 OutputStream outputStream = new FileOutputStream("D:/output.txt"); String str = "helloworld"; byte[] bytes = str.getBytes(); outputStream.write(bytes); outputStream.close(); /*********** * * 用法2 */ //在文件原来基础上append内容 OutputStream outputStream2 = new FileOutputStream("D:/output.txt", true); String str2 = "%% append "; byte[] bytes2 = str2.getBytes(); outputStream2.write(bytes2); outputStream2.close(); } }