5:10 pm - Monday April 24, 2017

Creating Program for Compare two abstract pathnames using int compareTo(File pathname)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This  Creating Program for Compare two abstract pathnames using

compareTo(File pathname) method.

EXAMPLE PROGRAM


import java.io.*;

public class FileComparepath {

public static void main(String[] args) {

File File1 = null;

File File2 = null;

File1 = new File(“Prop.xml”);

File2 = new File(“ArrayTask/aaa.txt”);

int value = File1.compareTo(File2);

String path1 = File1.getAbsolutePath();

String path2 = File2.getAbsolutePath();

System.out.println(path1 + “\n” + path2);

if (value == 0) {

System.out.println(“The Abstract Pathname of File1 = for File 2″);

}

if (value > 0) {

System.out.println(“The Abstract Pathname of File1 > for File 2″);

}

if (value < 0) { System.out.println("The Abstract Pathname of File1 < for File 2"); } System.out.println(value); } } [/java]  

Output

D:\Documents and Settings\Admin\MadhanTask\TasksCore\Prop.xml

D:\Documents and Settings\Admin\MadhanTask\TasksCore\ArrayTask\aaa.txt

The Abstract Pathname of File1 > for File2

15

Explanation

 

public int compareTo(File pathname)

 

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.

 

Specified by:

   compareTo in interface Comparable<File>

 

Parameters:

   pathname – The abstract pathname to be compared to this abstract pathname

 

Returns:

   Zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument

 

Since:

   1

BACK

Filed in: Z-A All Java Codes

Comments are closed.