简体   繁体   English

不使用BufferedOutputStream写入文件

[英]Not writing to file using BufferedOutputStream

Not writing content to file my code is fine from www.javaTpoint.com 从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");    
    }    
}

giving error at line 6 that remove argument from BufferedOutputStream or write constructor for it and at line 9,10 giving error that method write(b) and flush() are not defined for type BufferedOutputStream 在第6行给出了从BufferedOutputStream删除参数或为其写参数的错误,而在第9,10行给出了错误,未为BufferedOutputStream类型定义方法write(b)和flush()

The name of your class equals the one in the java.io package you're trying to use. 类的名称等于您要使用的java.io包中的名称。
You have 2 options: 您有2个选择:

1) Rename your class into MyBufferedOutputStream or something you like more. 1)将您的类重命名为MyBufferedOutputStream或您更喜欢的名称。

2) Change line 6 as follows: 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