A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to write Bytes using ByteStream
Q:

Java program to write Bytes using ByteStream

0

Here, we are using two classes 1) FileOutputStream and 2) DataOutputStream,

FileOutputStream class is using to create an object by passing file name and DataOutputStream class is using to create an object to invoke writeBytes() method to write data in the file.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class ExByteStreamFile 
{
    public static void main(String[] args) 
    {
        try
        {       
            // Here FO is the object of the file which is created to write.
            FileOutputStream FO=new FileOutputStream("E:/TH.txt");

            // Here F is the object of the file from which we have to write the content.
            DataOutputStream F=new DataOutputStream(FO);

            // These are the Input which is to be write on the file TH.txt
            F.writeBytes("Gwalior");
            F.writeBytes("\n");
            F.writeBytes("Indore");
            F.writeBytes("\n");
            F.writeBytes("Bhopal");
            F.writeBytes("\n");
            F.writeBytes("7008");
            F.writeBytes("\n");

            // FO colsed
            FO.close();
            // F closed
            F.close();

            //reading data
            FileInputStream FI=new FileInputStream("E:/TH.txt”);
            DataInputStream DI=new DataInputStream(FI);             
            String s="";                
            // This loop will print the whole whole inputted data on the screen
            while((s=DI.readLine())!=null)
            {
                System.out.println(s);
            }           
        }
        // If an error occurrs during the process
        catch(IOException e)
        {
            System.out.println(e);  
        }
    }
}

Output

 
Gwalior
Indore
Bhopal
7008

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now