Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Does file renaming always fail if the file is shared?

Reply
Thread Tools

Does file renaming always fail if the file is shared?

 
 
Chris
Guest
Posts: n/a
 
      03-06-2007
Suppose one process has a file open, and another process attempts to
rename the file. Is File.rename() always guaranteed to return false in
that case?

Does it at least work across all major operating systems?
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      03-06-2007
On Mon, 05 Mar 2007 21:25:24 -0600, Chris wrote:
> Suppose one process has a file open, and another process attempts to
> rename the file. Is File.rename() always guaranteed to return false in
> that case?
>
> Does it at least work across all major operating systems?


On many operating systems, it is possible to rename or even delete a
file while it is open by another process.

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
Ingo R. Homann
Guest
Posts: n/a
 
      03-06-2007
Hi,

Chris wrote:
> Suppose one process has a file open, and another process attempts to
> rename the file. Is File.rename() always guaranteed to return false in
> that case?
>
> Does it at least work across all major operating systems?


Depends what you call "all major operating systems". If you think of
about 90+% of all desktop PCs, then you are right: I suppose, that 90+%
of all desktop PCs either run with Windows XP, Windows 2000 or Windows
95. There it 'works' (which means that you *cannot* rename a 'shared' file).

However, using Linux or Unix, it does *not* work (which means that you
*can* rename the file

I'm not sure about the other 'exoticals' (like BeOS, Mac, and so on

Ciao,
Ingo

 
Reply With Quote
 
Jason Cavett
Guest
Posts: n/a
 
      03-06-2007
On Mar 6, 3:33 am, "Ingo R. Homann" <(E-Mail Removed)> wrote:
> Hi,
>
> Chris wrote:
> > Suppose one process has a file open, and another process attempts to
> > rename the file. Is File.rename() always guaranteed to return false in
> > that case?

>
> > Does it at least work across all major operating systems?

>
> Depends what you call "all major operating systems". If you think of
> about 90+% of all desktop PCs, then you are right: I suppose, that 90+%
> of all desktop PCs either run with Windows XP, Windows 2000 or Windows
> 95. There it 'works' (which means that you *cannot* rename a 'shared' file).
>
> However, using Linux or Unix, it does *not* work (which means that you
> *can* rename the file
>
> I'm not sure about the other 'exoticals' (like BeOS, Mac, and so on
>
> Ciao,
> Ingo


Windows 95

:: makes a face ::

Anyway, that's one question I've always had - shouldn't Java work the
same way across all OSes? Or does the way Java reacts depend on the
underlying OS (such as renaming a file via Windows vs. Linux).

 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      03-06-2007
Jason Cavett <(E-Mail Removed)> wrote:
> Anyway, that's one question I've always had - shouldn't Java work the
> same way across all OSes? Or does the way Java reacts depend on the
> underlying OS (such as renaming a file via Windows vs. Linux).


Java has to balance portability (working the same across all operating
systems) with usability (working the way users of the operating system
would expect). Perhaps it would be possible for Java to invent a scheme
to prevent itself from deleting an open file on Linux; but Linux users,
who are by and large knowledgable about how UNIX typically manages a
filesystem, would not expect it to do so. Using File in creative ways
is not transparently portable anyway (e.g., permissions issues), it
makes sense that Java would choose the other goal here.

--
Chris Smith
 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      03-06-2007
Hi Jason,

Jason Cavett wrote:
> Anyway, that's one question I've always had - shouldn't Java work the
> same way across all OSes? Or does the way Java reacts depend on the
> underlying OS (such as renaming a file via Windows vs. Linux).


Well, as Chris said: It has to be well-balanced.

To be extreme: Would you want to forbid 'System.getProperty("os.name")'
because it reacts differently on different OSs? Do you want to generally
forbid File-IO, because there are some embedded systems that do not have
something like a Harddisk (not to mention applets or webstart)? Should
the maximum size of a window that Java can use, be restricted to 80*40
pixel because that is the only resolution, that *every* hardware (even
mobile phones) supports? Should we forbid network-support?

The other extreme: Should sun invest some months of manpower (not to
mention legal problems) to 'hack' Windows so that Java can rename a file
that is opened by another program? Or should it hack Unix and Linux so
that the File can *not* be renamed, although it would be supported by
the OS?

I think the balance between the two extremes should be practical. And
that is what's happening at the moment.

Ciao,
Ingo


 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      03-06-2007
Chris wrote:

> Suppose one process has a file open, and another process attempts to
> rename the file. Is File.rename() always guaranteed to return false in
> that case?


Nope.

> Does it at least work across all major operating systems?


Windows and Unix behave differently in this (and it's part of the standard
semantics of their respective file-systems -- nothing Java specific).

-- chris


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Windopz will always fail on the desktop because it competes on price 7 Computer Support 1 11-12-2006 11:37 PM
Why does renaming a file not work when cron'd gd Perl Misc 4 02-06-2006 12:42 AM
ActiveDirectoryMembershipProvider login always fail Natan Vivo ASP .Net 1 10-31-2005 02:43 AM
Trying to create a CSS box that is always is always the width of an image placed inside it (and no wider) Deryck HTML 4 06-22-2004 08:25 PM
if (f() != FAIL) or if (FAIL != f())? Wenjie C Programming 3 07-31-2003 09:54 PM



Advertisments