Results 1 to 4 of 4
  1. #1
    javabarn is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default FileInputStream not recognising file

    I am having trouble with the following code getting error
    Buttons.java:339:cannot find symbol
    symbol :variable curFile
    location :class Buttons
    {FileInputStream f_in = new FileInputStream(curFile);
    ^

    I have put a system.out line above and it recognises it there

    A similar dialog for writing seems to be accepted


    Java Code:
    {teachPanel.setVisible(true);
    	questPanel.setVisible(false);	
    	File f = new File(thingsName+".zzz");// set to existing file
    	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        	chooser.setSelectedFile(f);
        	int returnVal=chooser.showOpenDialog(null);
    	if (returnVal == JFileChooser.APPROVE_OPTION)//file selected
    
    		{File curFile=new File("");
    	 curFile = chooser.getSelectedFile();
          	System.out.println("File Type= "+curFile);}
    	else {return;}
    	//read file here 
    	try
    		{FileInputStream f_in = new FileInputStream (curFile);  //problem line
    
    		ObjectInputStream obj_in = new ObjectInputStream (f_in);
    		Object obj=obj_in.readObject();
    		scores =(int[][]) obj; //cast obj to array
    		Object obj1=obj_in.readObject();
    		props=(String[])obj1;
    		Object obj2=obj_in.readObject();
    		things=(String[])obj2;}
    /

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    12

    Default

    curFile is out of scope, you define it in the if block, and that's the only place where it's visible.

    And your bracing style is atrocious!
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    javabarn is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Thumbs up solved

    PhHein,
    many thanks -had looked at it for ages - the braces are the result of frustrated attempts to get to the bottom of it. I was thrown by the similar code working for writing - but if scope was different there

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    12

    Default

    Glad you sorted it out, please mark the thread as solved in the thread tools menu above your original post.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. FileInputStream
    By pachufir in forum New To Java
    Replies: 3
    Last Post: 12-11-2009, 05:07 PM
  2. NullPointerException in FileInputStream text file
    By cheskers11 in forum Eclipse
    Replies: 1
    Last Post: 11-19-2009, 01:38 PM
  3. FileOutputStream > int > FileInputStream
    By dudejonne in forum New To Java
    Replies: 11
    Last Post: 11-11-2009, 04:03 PM
  4. Replies: 13
    Last Post: 09-16-2009, 01:05 PM
  5. Replies: 0
    Last Post: 12-01-2008, 09:50 PM

Posting Permissions

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