package study;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
//这种会覆盖文件的原本内容
public class Exercise {
public static void main(String[] args) {
//1.创建源
File f=new File("E:\\临时\\BBB.txt"); //没有此文件是会自动创建
//2.选择流
OutputStream o=null;
try {
o=new FileOutputStream(f);
//3.操作
String str="hello java";
byte[] b=str.getBytes(); //字符->字节==编码
o.write(b, 0, str.length());
o.flush(); //强制刷新,释放内存,最好习惯写这个
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
o.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}