//Java program to Perform Byte Stream Using
File.
import java.io.*;
import java.util.*;
class bytestream
{
public static void main(String args[])throws
IOException
{
int
b1,i,n;
OutputStream fodd=new FileOutputStream("odd");
OutputStream feven=new FileOutputStream("even");
Scanner s=new Scanner(System.in);
System.out.println("Enter Number Of Data :");
n=s.nextInt();
System.out.println("Data's :");
try
{
for(i=0;i<n;i++)
{
b1=s.nextInt();
if(b1%2==0)
feven.write(b1);
else
fodd.write(b1);
}
}
catch(NumberFormatException e)
{
System.out.println("Number Is Only Allowed");
}
fodd.close();
feven.close();
InputStream f=new FileInputStream("odd");
InputStream f1=new FileInputStream("even");
System.out.println("odd Numbers are :");
while((b1=f.read())!=-1)
System.out.println(b1);
System.out.println("Even Numbers are :");
while((b1=f1.read())!=-1)
System.out.println(b1);
f.close();
f1.close();
}
}
No comments:
Post a Comment