How to improve the efficiency of writing data into a file using BufferedOutputStream. - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
How to improve the efficiency of writing data into a file using BufferedOutputStream.

How to improve the efficiency of writing data into a file using BufferedOutputStream.





// Text file using BufferedOutputStream
import java.io.*;
class CreateFileDemo
{
public static void main(String[]arr)
throws IOException{
// attch keybord to DataInputStream
         DataInputStream dis=new DataInputStream(System.in);
         // attch myfile to fileOutputStream in append mode.
         FileOutputStream fout =new FileOutputStream("myfile.txt",true);
         // attch FileOutputStream to BufferedOutputStream
         BufferedOutputStream bout=new BufferedOutputStream(fout,1024);
         System.out.println("Enter the text (@ at the end):");
         char ch;
         // read character from dis into ch . Then write them into bout .
         // repeat this as long as the read Character is not @

         while((ch=(char)dis.read()) !='@')
          bout.write(ch);
         //close the file
         bout.close();

}
}

That is Output

E:\ShashiJava>javac CreateFileDemo.java
E:\ShashiJava>java CreateFileDemo
Enter text (0 to the end)
Hello I am Shahsi This File No Is One
Hello I am Shahi This File No Is Two
@
E:\ShashiJava>myfile.txt
E:ShashiJava>
This is my file line one
This is my file line two 
Hello I am Shahsi This File No Is One
Hello I am Shahi This File No Is Two


About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.