`
java-_-ted
  • 浏览: 12144 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

初识字节流----FileOutputStream

 
阅读更多
import java.io.FileOutputStream;
/*
 * FileOutputStream
 * 1.通过write()方法进行写操作
 * 2.如果文件不存在,FileOutputStream可以创建文件
 * 3.必须关闭流
 */
public class FileOutputStreamTest {

	public static void main(String[] args) throws Exception{
		//实例化FileOutputStream对象
		//定义true的含义是,不覆盖文本以前内容.
        FileOutputStream fo = new FileOutputStream("c:/MyDoc/hello.txt",true);
        String str = "TEST";
        //转换类型
        byte[] words = str.getBytes();
        fo.write(words);
        System.out.println("文件已经更新");
        //关闭流
        fo.close();
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics