- package com.io;
- import java.io.*;
- public class TestOutputStream
- { public static void main(String[] args)
- {
- OutputStream os=null;
- try
- {
- os=new FileOutputStream(new File("res/test.txt"));
- // 向文件中写入数据
- String content="good morning";
- byte[] data=content.getBytes();
- os.write(data);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- os.close();// 关闭输出流
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2659936.html