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 / March 2007

Tip: Looking for answers? Try searching our database.

Does file renaming always fail if the file is shared?

Thread view: 
Chris - 06 Mar 2007 03:25 GMT
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?
Gordon Beaton - 06 Mar 2007 05:57 GMT
> 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

Signature

[ 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

Ingo R. Homann - 06 Mar 2007 08:33 GMT
Hi,

> 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
Jason Cavett - 06 Mar 2007 14:25 GMT
> Hi,
>
[quoted text clipped - 16 lines]
> 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).
Chris Smith - 06 Mar 2007 14:45 GMT
> 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.

Signature

Chris Smith

Ingo R. Homann - 06 Mar 2007 15:07 GMT
Hi Jason,

> 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
Chris Uppal - 06 Mar 2007 18:08 GMT
> 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


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



©2009 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.