[ale] OT: java filereader question
J.M. Taylor
jtaylor at onlinea.com
Thu Apr 8 20:42:11 EDT 2004
Greetings all,
I need to evaluate a condition and decide whether to open file1 or file2
based on that condition. Obviously I can do
if (conditional) {
FileReader fr = new FileReader("file1");
}
else {
FileReader fr = new FileReader("file2");
}
However, with my undisciplined scripting language background I would like
to do something like
File filename = (conditional ? "file1" : "file2");
FileReader fr = new FileReader(filename);
I can do the ternary operator if I declare filename as a String, but then
FileReader won't open it (the parameter must be a File object).
new FileReader((File)filename)
doesn't work either.
Nor does
FileReader fr = (conditional ? new FileReader("file1") : new
FileReader("file2"));
Nor does
FileReader fr = new FileReader((conditional ? "file1" : "file2"));
I don't use Java very much, but I like to understand what's going on (and
why I can and can't do things from language to language) as much as
possible. If anybody out there in aleland uses Java and can help me out,
I would greatly appreciate it. I won't be offended if you tell me why I'm
being brain-dead, if that is in fact the case.
Thanks
jenn
--
Jenn Taylor
jtaylor at onlinea.com
------------------------------------------------------------------------
Obviously, a man's judgement cannot be better than the information on which he
has based it. Give him the truth and he may still go wrong when he has
the chance to be right, but give him no news or present him only with distorted
and incomplete data, with ignorant, sloppy or biased reporting, with propaganda
and deliberate falsehoods, and you destroy his whole reasoning processes, and
make him something less than a man.
-- Arthur Hays Sulzberger
More information about the Ale
mailing list