Solved programming problem

Write data in .txt File with Output Stream in Java.

Source code

package outputstream;

import java.io.FileOutputStream;

import java.io.IOException;

public class OutputStream {

 

    public static void main(String[] args)

    {

        String df = "output.txt";

        String str = "Code "+ "to " +"HaveN";

     

        try

        {

            FileOutputStream fos =new FileOutputStream(df);

            fos.write(str.getBytes());

            fos.flush();

            fos.close();

        }

        catch(IOException e)

        {

            e.printStackTrace();

        }

    }

 

}

Output

Output:

NB: A .txt file will be Create and We Can See This

Join the discussion

Add your comment