aspose file tools*
The moose likes Beginning Java and the fly likes Simple file question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple file question" Watch "Simple file question" New topic
Author

Simple file question

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635



It has problem about this line:





Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That's because that variable is declared inside of the try block and because of that it's not visible from outside of the try block.
The solution: declare the variable outside of the try block and initialize it inside of it.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
I'm going to guess that your compiler complains about the variable "inchar", because it is out of scope on that line. You declare it within the braces of your "try" block, so it is not visible within the braces of the "finally" block.

I have to guess because you have not provided us with an error message. In the future, I recommend that you give a little more information about what the problem really is -- if this had not been pretty obvious to me, I wouldn't have made a guess, and I wouldn't have searched hard. To get good help with questions, you need to provide folks with as much information as you can easily get, at least.

You might also try looking at the error message. One of the really good things about Java is the accuracy of its compiler's messages, i.e., it *usually* tells you exactly what is wrong and where.

rc
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635


Any suggestion to make it better?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

abalfazl hossein wrote:It has problem about this line:
Please read our FAQs on why ItDoesntWorkIsUseless and why you should TellTheDetails.

(you can click on those phrases to be taken directly to the specific FAQ).


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

abalfazl hossein wrote:Any suggestion to make it better?

How about a null check? What will happen if the FileInputStream cannot be created? In other words, if line 12 throws an exception?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple file question