クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
Visual Studio 2005
Visual Studio ドキュメント
Visual J#
Visual J# リファレンス
Visual J# Class Library
java.io
File Class
File Methods
compareTo Method
 compareTo Method (Object)
すべて縮小/すべて展開 すべて縮小
Visual J# Reference
File.compareTo Method (Object)

Compares one File object with another object.

Package: java.io

Assembly: vjslib (in vjslib.dll)

public int compareTo(
    java.lang.Object o);

Parameters

o

An object representing a file or folder to compare against.

Less than zero if the path and name of the object calling compareTo is alphabetically less than the object o, 0 if the path and name of the object calling compareTo is alphabetically equal to the object o, and greater than zero if the path and name of the object calling compareTo is alphabetically greater than the object o.

The following example demonstrates how to compare two file names alphabetically.

// file_compareto_2.jsl

import java.io.*;

public class Program
{
    public static void main(String[] args)
    {
        // Open the file C:\MyFile.txt.
        Object myFile = new File("C:\\MyFile.txt");

        // Open the file C:\YourFile.txt.
        Object yourFile = new File("C:\\YourFile.txt");

        if (myFile instanceof File &&
            yourFile instanceof File &&
            ((File)myFile).exists() && ((File)yourFile).exists())
        {
            // Compare the two files alphabetically.
            int compareResult = ((File)myFile).compareTo(yourFile);

            // Display the results of the comparison.
            if (compareResult < 0)
            {
                System.out.println(((File)myFile).getAbsolutePath() +
                    " is less than " +
                    ((File)yourFile).getAbsolutePath());
            }
            else if (compareResult == 0)
            {
                System.out.println(((File)myFile).getAbsolutePath() +
                    " is equal to " +
                    ((File)yourFile).getAbsolutePath());
            }
            else
            {
                System.out.println(((File)myFile).getAbsolutePath() +
                    " is greater than " +
                    ((File)yourFile).getAbsolutePath());
            }
        }
    }
}

/*
Output:
C:\MyFile.txt is less than C:\YourFile.txt
*/
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2010 Microsoft Corporation. All rights reserved. 使用条件 | 商標 | プライバシー
Page view tracker