Detecting Equivalence between Two Files

K

kvnsmnsn

When I'm in the "emacs" editor on a file in a directory, and have made
changes to that file that I haven't saved, and then open up a window
on a file in another directory that happens to be a symbolic link to
the file I had already been editing, "emacs" can tell that I've opened
another window on the same file, and therefore brings up another copy
of the buffer that I'd edited complete with all my unsaved changes to
it.

Is there some way to tell this in Java in general? If I open one file
in a Java program, make changes to it, and then the user requests the
opening of a file with a different path name that happens to be the
same as the first file, can Java detect that it's the same file and
therefore not reopen it?

If anyone can point me to some information on this I'd greatly appre-
ciate it.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
P

Papastefanos Serafeim

Well, I believe that emacs is doing that by checking if the file
being opened is a symbolic link with an already opened file...

To do that in java, you can probably use the method
getCanonicalPath() of the File class.
 
K

kvnsmnsn

Papastefanos Serafeim posted:

=Well, I believe that emacs is doing that by checking if the file
=being opened is a symbolic link with an already opened file...
=
=To do that in java, you can probably use the method
=getCanonicalPath() of the File class.

Thanks! I was able to write a Java program using <getCanonicalPath()>
that recognized equivalences in files no matter what path name I spe-
cified.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top