简体   繁体   中英

Not writing to file using BufferedOutputStream

Not writing content to file my code is fine from 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

The name of your class equals the one in the java.io package you're trying to use.
You have 2 options:

1) Rename your class into MyBufferedOutputStream or something you like more.

2) Change line 6 as follows:
java.io.BufferedOutputStream bout=new java.io.BufferedOutputStream(fout);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM