<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">package com.hfxt;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
//输出流(写入)
public class FileOutPutStreamDemo {
public static void main(String[] args) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream("F:/fangchen/test1.txt");
String str = "我要努力学java!";
//把字符串打散为字节数组
byte [] words = str.getBytes();
//写入文件
fos.write(words,0,words.length);
//提示
System.out.println("文件已被更新!");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
</span></strong>