Home arrow static arrow Java Programming [Archive] - file 'con.model' exists when it doesn't
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - file 'con.model' exists when it doesn't
This topic has 3 replies on 1 page.

Posts:5
Registered: 11/18/01
file 'con.model' exists when it doesn't  
Aug 5, 2004 12:37 PM



 
I'm having trouble that if I the following code

new File("con.model").exists()

seems to always return true. I'm running on a Windows machine, and I believe this is because of the weird way Windows treats "con". I went to the directory and tried to delete "con.model", both through the command prompt and through cygwin, but neither one can find such a file. This makes me think that maybe Windows always reports that this file exists when asked...?

Anyway, is there a way to work around this? Or maybe something else I might be doing wrong?

Steve
 

Posts:594
Registered: 5/2/01
Re: file 'con.model' exists when it doesn't  
Aug 5, 2004 12:44 PM (reply 1 of 3)



 
Just tested this on Win2K and I get the same odd result. Can't think of a way around it other than using a different name. Seems anything starting with "con" will always return true.
 

Posts:5
Registered: 11/18/01
Re: file 'con.model' exists when it doesn't  
Aug 5, 2004 12:47 PM (reply 2 of 3)



 
Good, I'm glad I'm not just totally insane. =)

Yeah, I was trying to avoid hardcoding the restriction that "con" not be a name, in case my code gets run on another platform, and my user has happened to name their file 'con.model'.
 

Posts:3,055
Registered: 18/06/98
Re: file 'con.model' exists when it doesn't  
Aug 6, 2004 5:53 AM (reply 3 of 3)



 
The following file names in Windows are "reserved" because they represent devices:
con, con.* -> the console
prn, prn.* -> the default printer, as a character device
aux, aux.* -> the default serial terminal, as a character device
lpt1, lpt2, lpt3, lpt4, lpt5, lpt6, lpt7, lpt8, lpt9 -> the parallel ports, as character devices
lpt1., lpt2., lpt3., lpt4., lpt5., lpt6., lpt7., lpt8., lpt9.*
com1, com2, com3, com4, com5, com6, com7, com8, com9 -> the serial ports, as character devices
com1., com2., com3., com4., com5., com6., com7., com8., com9.*
nul, nul.* -> the NUL or "waste bit bucket" or "black hole for bits" or "/dev/null" device

Such files are considered to "exist" in all directories, so if you have a filename like "c:\temp\con", you're talking about the CON device, not about a normal disk file called "con". They're not listed using the "dir" command, or using APIs.

This is an inheritance from good old DOS days. (In Unix such files are placed in the /dev directory...)

You can have a normal file named "conX", but the file "con.X" is considered as the console.
 
This topic has 3 replies on 1 page.