hello frndz,
i was doing this program and then i encountered this strange problem...
it is a program in which i want to open two text files and then compare it..
It is giving me two errors:
1)variable f1 might not be initialised.
2)variable f2 might not be initialised.
and when i include a return statement in the catch blocks,it works....i cant understand why is it so
because it doesnt throw any exception...plz help...thanks
/*
Project 10-1
Compare two files.
To use this program, specify the names
of the files to be compared
on the command line.
java CompFile FIRST.TXT SECOND.TXT
*/
import java.io.*;
class compare_files
{
public static void main(String p[])
{
int i=0,j=0;
FileInputStream f1,f2;
try
{
try
{
f1=new FileInputStream(p[0]);
}
catch(IOException e)
{
System.out.println("Can't open the file!");
}
try
{
f2=new FileInputStream(p[1]);
}
catch(IOException e)
{
System.out.println("Can't open the file!");
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array out of bounds!");
}
try
{
do
{
i=f1.read();
j=f2.read();
if(i!=j)
break;
}while(i!=-1||j!=-1);
}
catch(IOException e)
{
System.out.println("I/O Exception!");
}
if(i==j)
System.out.println("Both files are same");
else
System.out.println("Both files are different");
}
}