Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Odd file.exists() problem

Thread view: 
O.B. - 27 Jan 2006 22:51 GMT
I'm hoping there is just something syntactically wrong with the
following.  I've verified that the file exists, but it keeps saying that
it doesn't.  Thoughts?

String filename = "C:\\Java\\j2sdk1.4.2_10\\jre\\bin\\java";
File testFile = new File(filename);
if (testFile.exists()) {
  System.out.println(filename + " exists.");
} else {
  System.out.println(filename + " does not exist.");
}
Oliver Wong - 27 Jan 2006 22:54 GMT
> I'm hoping there is just something syntactically wrong with the following.
> I've verified that the file exists, but it keeps saying that it doesn't.
[quoted text clipped - 7 lines]
>   System.out.println(filename + " does not exist.");
> }

   Might you be thinking "java.exe" instead of "java"?

   - Oliver
O.B. - 27 Jan 2006 22:54 GMT
> I'm hoping there is just something syntactically wrong with the
> following.  I've verified that the file exists, but it keeps saying that
[quoted text clipped - 7 lines]
>   System.out.println(filename + " does not exist.");
> }

Darn ... I hit send too early.  My UNIX background got the best of me;
I'm missing ".exe".  Argh!
Knute Johnson - 28 Jan 2006 00:38 GMT
>> I'm hoping there is just something syntactically wrong with the
>> following.  I've verified that the file exists, but it keeps saying
[quoted text clipped - 10 lines]
> Darn ... I hit send too early.  My UNIX background got the best of me;
> I'm missing ".exe".  Argh!

You've probably just typed something wrong somewhere.  Since you are a
unix fan you can use the / instead of the \\.

Signature

Knute Johnson
email s/nospam/knute/

Raymond DeCampo - 30 Jan 2006 14:46 GMT
>>> I'm hoping there is just something syntactically wrong with the
>>> following.  I've verified that the file exists, but it keeps saying
[quoted text clipped - 13 lines]
> You've probably just typed something wrong somewhere.  Since you are a
> unix fan you can use the / instead of the \\.

Only if you want to break any routine that depends on File.separator.

Ray

Signature

This signature intentionally left blank.

Chris Uppal - 30 Jan 2006 15:31 GMT
> > You've probably just typed something wrong somewhere.  Since you are a
> > unix fan you can use the / instead of the \\.
>
> Only if you want to break any routine that depends on File.separator.

Any routine that depends carelessly on File.separator being the /only/
allowable path separator for the platform is already broken.

'/' has been a legal path separator on M$-ware since at least MS-DOS 3.

Incidentally, the Sun implementation of File normalises paths to use '\\'
throughout (on Windows).  That's probably a good idea, since otherwise
File.separator would be totally useless rather than merely dangerously
misleading.  But I don't know if it is documented to do so; if not then relying
on that aspect of its behaviour may not be justifiable in production code.

   -- chris
Dimitri Maziuk - 30 Jan 2006 17:22 GMT
Chris Uppal sez:

>> > You've probably just typed something wrong somewhere.  Since you are a
>> > unix fan you can use the / instead of the \\.
[quoted text clipped - 11 lines]
> misleading.  But I don't know if it is documented to do so; if not then relying
> on that aspect of its behaviour may not be justifiable in production code.

I don't know what File normalises paths to, but IME
"some/path/some/file" works on both unix and winders whereas
"\\some\\path\\some\\file" is M$-only. Handy when you want to
read paths from a properties file.

Another undocumented trick is "java foo/bar/MyClass" -- you can
use tab-completion on unix command line.

Dima
Signature

Backwards compatibility is either a pun or an oxymoron.                  -- PGN

Roedy Green - 30 Jan 2006 22:04 GMT
On Mon, 30 Jan 2006 14:46:37 GMT, Raymond DeCampo
<nospam@twcny.rr.com> wrote, quoted or indirectly quoted someone who
said :

>>>> String filename = "C:\\Java\\j2sdk1.4.2_10\\jre\\bin\\java";

your file is called "java..exe" not "java"
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Daniel Dyer - 27 Jan 2006 22:54 GMT
> I'm hoping there is just something syntactically wrong with the  
> following.  I've verified that the file exists, but it keeps saying that  
[quoted text clipped - 7 lines]
>    System.out.println(filename + " does not exist.");
> }

I think you are missing the file extension.  Shouldn't it be "java.exe"?  
If you are viewing the directory in Windows Explorer it hides known file  
extensions by default.

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.