簡體   English   中英

不使用BufferedOutputStream寫入文件

[英]Not writing to file using BufferedOutputStream

從www.javaTpoint.com可以不寫內容來歸檔我的代碼

package JavaIO;
import java.io.*;
public class BufferedOutputStream {
    public static void main(String args[])throws Exception{    
         FileOutputStream fout=new FileOutputStream("/home/ebryx/myFile.txt");    
         BufferedOutputStream bout=new BufferedOutputStream(fout);    
         String s="I am Writing to file.";    
         byte b[]=s.getBytes();    
         bout.write(b);    
         bout.flush();    
         bout.close();       
         System.out.println("success");    
    }    
}

在第6行給出了從BufferedOutputStream刪除參數或為其寫參數的錯誤,而在第9,10行給出了錯誤,未為BufferedOutputStream類型定義方法write(b)和flush()

類的名稱等於您要使用的java.io包中的名稱。
您有2個選擇:

1)將您的類重命名為MyBufferedOutputStream或您更喜歡的名稱。

2)更改第6行,如下所示:
java.io.BufferedOutputStream bout=new java.io.BufferedOutputStream(fout);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM