java文件输出流 FileOututStream

文档地址 http://tool.oschina.net/apidocs/apidoc?api=jdk-zh
与FileInputStream相对应
构造方法
FileOutputStream(File file)
FileOutputStream(File file, boolean append) 向文档的末尾追加
FileOutputStream(FileDescriptor fdObj)
FileOutputStream(String name)
FileOutputStream(String name, boolean append)

方法
write(byte[] b) 将 b.length 个字节从指定 byte 数组写入此文件输出流中。
write(byte[] b, int off, int len) 将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此文件输出流。
write(int b) 将指定字节写入此文件输出流。
void init() throws IOException {
FileOutputStream fos = new FileOutputStream("…/…/…/desktop/test/1.txt");
try {
byte[] b =new byte[] {
99,100,101,102,103,104,105,106,107,108
};
fos.write(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
fos.close();
}
}

猜你喜欢

转载自blog.csdn.net/weixin_41069726/article/details/86506617