This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes compareTo() function doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "compareTo() function doubt" Watch "compareTo() function doubt" New topic

compareTo() function doubt

Anupama Sudhakaran

Joined: Feb 22, 2010
Posts: 18
can anyone tell me how does the comparing take place between 2 files using compareTo() belonging to the File API. whether it only compares the path names or the contents of the File?
Thank you in advance
Rob Spoor

Joined: Oct 27, 2005
Posts: 19556

If you would have read the Javadoc of you would have seen the following:
Compares two abstract pathnames lexicographically. The ordering defined by this method depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.

So no, it doesn't check the contents, just the result of getPath().

Whoops, quote tags, not code tags!

How To Ask Questions How To Answer Questions
Anupama Sudhakaran

Joined: Feb 22, 2010
Posts: 18
Thank you
I agree. Here's the link:
subject: compareTo() function doubt
Similar Threads
accessing .newsrc files...
can anyone explain me about compareTo()
how to find the difference between Dates
Comparing two huge files
Numberformat exception