使用字节缓冲流在文件中写内容
package text;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Buff2 {
? ? ?public static void main(String[] args) {
?? ??? ?BufferedOutputStream bos=null;
?? ??? ?try {
//?? ??? ? ?? ?使用字節(jié)緩沖在文件中寫內(nèi)容
?? ??? ??? ? bos=new BufferedOutputStream(new FileOutputStream("D:\\IO\\java.txt",true));
//?? ??? ??? ? 寫入內(nèi)容
?? ??? ?? ? ?bos.write(65);
//?? ??? ?? ? ?寫入字符串
?? ??? ?? ? ?byte []b="hello word\r\nhttp".getBytes();
?? ??? ? ?? ?bos.write(b);
//?? ? ?? ??? ?截取的內(nèi)容重一遍
?? ?? ? ??? ?bos.write(b,1,3);
?? ??? ??? ?
?? ??? ??? ?
?? ? ?? ?} catch (IOException e) {
?? ??? ??? ?
?? ??? ??? ? e.printStackTrace();
?? ? ?? ?}finally{
?? ??? ?? ? ?if(bos!=null){
?? ??? ??? ??? ? try {
?? ??? ??? ?? ? ??? ?bos.close();
?? ??? ??? ? ?? ?} catch (IOException e) {
?? ??? ??? ??? ??? ?e.printStackTrace();
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ?}
}
轉(zhuǎn)載于:https://www.cnblogs.com/hph1728390/p/10602083.html
總結(jié)
以上是生活随笔為你收集整理的使用字节缓冲流在文件中写内容的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: SSAS Tabular模式中关系设置不
- 下一篇: 2019_BUAAOO_第一单元总结