Hi,
I am using IBM's RAD as my IDE. In my servlet, I have coded:
// set the filename for the server side repository ...
serverFileName = "/web/UserSource/" + user + "-" + shortFileName;
// Open up the output file on server ...
FileOutputStream fos = new FileOutputStream(serverFileName);
Writer outf = new OutputStreamWriter(fos,"Cp1047");
The above logic is inside an "if" construct, as I only can set the file
name after some information is retrieved.
Afterwards, outside of this "if", I try to write to the file like so,
(another "if"):
if (cnt > 4 && !prevLine.equals(boundary)) {
outf.write(prevLine);
out.println("<br>" + prevLine);
}
The outf.write(prevLine) statement is flagged as "outf cannot be resolved"
why, since I have previously defined it? How do I correct this error?
Thanks,
Larry
Rhino - 13 Sep 2006 17:12 GMT
> Hi,
>
[quoted text clipped - 21 lines]
>
> why, since I have previously defined it? How do I correct this error?
This is a scope issue. You defined 'outf' in one branch of the 'if' so it is
not visible in the 'else' side. Move the definition of 'outf' (and 'fos') to
outside of the 'if' altogether and everything should be fine.
--
Rhino
GoHabsGo - 13 Sep 2006 17:39 GMT
>> Hi,
>>
[quoted text clipped - 31 lines]
> --
> Rhino
Thanks Rhino. I can not move the definitions. I defined outf = null
outside of any constructs and that worked.