Results 1 to 2 of 2
  1. #1
    mahinkhan22 is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Post Stream Object Initialization

    Now I am getting compile time error at line 30 and 38 that 'fin' might not have been initialized. but its perfectly to write it this way
    Java Code:
    import java.io.*;
    class CopyFile {
    	public static void main(String args[]) throws IOException {
    		int i;
    		FileInputStream fin;
    		FileOutputStream fout= new FileOutputStream(args[1]);
    
    		try{
    			//open input file
    			try{
    				fin = new FileInputStream(args[0]);
    			}
    			catch(FileNotFoundException e){
    				System.out.println("Input file Not Found");
    				return;
    			}
    			//open output file
    			try{
    				fout = new FileOutputStream(args[1]);
    			}
    			catch(FileNotFoundException e){
    				System.out.println("Error Opening File");
    			}
    		}
    		catch(ArrayIndexOutOfBoundsException e){
    			System.out.println("usage: Copyfile From to");
    		}
    		try{
    			do{
    				i = fin.read();
    				if(i!= -1)
    					fout.write(i);
    			}while(i != -1);
    		}
    		catch(IOException e){
    			System.out.println("file error");
    		}
    		fin.close();
    		fout.close();
    	}
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Stream Object Initialization

    It`s a local variable! Try to write FileInputStream fin = null; in line 5

Similar Threads

  1. Array of object initialization
    By rybo85 in forum New To Java
    Replies: 8
    Last Post: 05-03-2012, 06:49 AM
  2. Problem with Object Stream
    By er.raj in forum New To Java
    Replies: 6
    Last Post: 03-13-2012, 04:38 PM
  3. Input Stream as an Object?
    By sehudson in forum New To Java
    Replies: 1
    Last Post: 03-12-2011, 01:37 AM
  4. Object Input Stream EOFException
    By FlyNn in forum New To Java
    Replies: 1
    Last Post: 12-18-2010, 01:33 PM
  5. Replies: 0
    Last Post: 07-08-2009, 09:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •