import java.io.*;
public class TestEncode {
public static void main(String[] args) {
//自动创建相对路径下文件
File f = new File("fileTest.txt");
OutputStream os = null;
try {
//选择流 append:true
os = new FileOutputStream(f,true);
String str = "hello world";
//string.getBytes() String---->字符数组
byte[] b = str.getBytes();
//length
os.write(b,0,b.length);
//刷新缓存区
os.flush();
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}finally {
//关闭,释放资源
if(os != null) {
try {
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
FileOutputStream
最新推荐文章于 2024-08-14 11:46:33 发布