http://www.verejava.com/?id=1699464804818
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();
}
}
}
}

本文介绍了一个使用Java的FileOutputStream类将字符串goodmorning写入到名为test.txt的文件中的示例。该示例展示了如何创建输出流、写入数据以及正确关闭资源。
1656

被折叠的 条评论
为什么被折叠?



