import java.io.*;
public class FileEx
{
public static void main(String ar[])
{
int i;
try{
FileInputStream fodd = new FileInputStream("dataodd.txt");
FileOutputStream fin = new FileOutputStream("data.txt");
FileInputStream feven = new FileInputStream("dataeven.txt");
while((i=fin.read()) != -1)
{
if(i%2==0)
feven.write(i);
else
fodd.write(i);
}
fodd.close();
fin.close();
feven.close();
}catch(Exception e){
}
}
}
I want to find even and odd number from any text file and store even numbers in one text file(i.e. dataeven.txt) and odd numbers in another file(i.e. dataodd.txt). I have tried it to much times but i didn't find error,it shows error like "cannot find symbol" like below:
Program name is FileEx.java.
i am using 1.8.0_25 version of JDK and 1.8.0_45 version of JRE
FileOutputStream
does not have a read
method and FileInputStream
does not have a write
method.
You are simply messing up the streams here: you read from an InputStream
and write to an OutputStream
.