Request Urgent Help - open directory to read contents, with ActiveDirectory running

D

Daku

Could some Java guru please kindly help ? I am porting
an application from Linux to Windows (with Active
Directory running), and getting into very odd problems.
I am using Eclipse IDE.

I want to open a directory as:
File infile = new File ("C:/temp");
......
Then :
if(infile != null)
{
try
[
infile.createNewFile();
}
catch(IOException ioe)
{
}

if(infile != null && infile.isDirectory())
{ // Do some processing
}

The test -- infile != null passes, but infile.isDirectory()
does not. All processing inside the if block depends
on infile being a directory.

Any hints suggestions would be of immense help.
 
E

Eric Sosman

Could some Java guru please kindly help ? I am porting
an application from Linux to Windows (with Active
Directory running), and getting into very odd problems.
I am using Eclipse IDE.

I want to open a directory as:
File infile = new File ("C:/temp");
.....
Then :
if(infile != null)

Unless you've set infile=null somewhere in the "....."
part, the condition is guaranteed to be true. What are you
trying to test here? Do you realize that the test you're
actually making says nothing at all about what is or is not
on the file system?

... proving that the code you've showed us cannot possibly
be the code you're actually using. If the problems and remedies
people point out in what you've shown don't help with the
difficulty you're having, it's entirely your fault. "Doctor,
I have this terrible pain in my ankle -- whenever I swallow."
infile.createNewFile();

What are you trying to do? This will (try to) create a
new file if none exists already, or will leave an existing
file untouched. And it will report what it did or didn't do
by returning a true or false value -- but since you ignore
that value, what's the point? You can be sure that a file
exists, but you can also be sure that if it exists because
this call created it, then the newly-created file will *not*
be a directory.
}
catch(IOException ioe)
{

Bad Daku! Bad! Bad! Bad!
}

if(infile != null&& infile.isDirectory())

Again, the first part of the test is silly. The second
will succeed only if the file existed before your code ran
(because if it didn't, the new file you create will be an
ordinary data file and not a directory).
{ // Do some processing
}

The test -- infile != null passes, but infile.isDirectory()
does not.

Exactly as expected. Why do you find this surprising?
All processing inside the if block depends
on infile being a directory.

Any hints suggestions would be of immense help.

What are you trying to do? I can offer help like "Buy
low, sell high" but unless I know your goal it's hard to
be more specific.

... and none of this seems to have anything at all to
do with Active Directory. So, again: What's your goal?
 
Joined
Dec 31, 2009
Messages
6
Reaction score
0
hii,

Code:
 File infile = new File ("C:/temp");

should be "c:\\someFileName"

... kopik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top