Java program which accepts a list of existing text files from command line arguments
<blockquote>
  <p>Question: write a Java program which accepts s list of existing text files from command line args and concatenates the contents of all files in "Master.txt".</p>
</blockquote>

<p>My code gives an error while testing 4 <code>endsWith(".txt")</code>. Please let me know how to correct it.</p>

<pre><code>import java.io.*;
class FileConcat
{
 public static void main(String[] args)
 {
  FileOutputStream fout;
  FileInputStream fin,fin1;
  File f;
  int b; 
  try
  {
   //open Master file
   try
   {
    fout=new FileOutputStream("Master.txt"); 
   }
   catch(Exception e)
   {
    System.out.print(e.getMessage());
   }
   //traverse all args, check if valid text file, if yes, concatinate
   for(int j=0;j&lt;args.length;j++)
   {
    f=new File(args[j]);
    if(f.isFile()==true)
    {
     if((args[j].endsWith(".txt"))==true)
     {
      try
      {
       fin=new FileInputStream(args[j]);
      }
      catch(Exception e)
      {
       System.out.print("Error Opening "+args[j]);
      }
      while((b=fin.read())!=-1)
      {
       char ch=(char) b;
       fout.write(ch);
      }
     }
    fin.close();
    }
   }
   fout.close();
   fin1=new FileInputStream("Master.txt"); 
   while((b=fin1.read())!=-1)
   {
    char ch=(char) b;
    System.out.print(ch);
   }
   fin1.close();
  }
  catch(Exception e)
  {
   System.out.println(e.getMessage());
  }
 }
}
</code></pre>

<p>The output:</p>

<pre><code>C:\j2sdk1.4.1_01\bin&gt;javac FileConcat.java
FileConcat.java:38: variable fin might not have been initialized
                                                while((b=fin.read())!=-1)
                                                         ^
FileConcat.java:41: variable fout might not have been initialized
                                                        fout.write(ch);
                                                        ^
FileConcat.java:44: variable fin might not have been initialized
                                fin.close();
                                ^
FileConcat.java:47: variable fout might not have been initialized
                        fout.close();
                        ^
4 errors
</code></pre>

<p>How do I check if <code>fin</code> is assigned a value or not?</p>
