home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / File.java < prev    next >
Text File  |  1997-05-20  |  26KB  |  682 lines

  1. /*
  2.  * @(#)File.java    1.49 97/05/04
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.io;
  24.  
  25. import java.util.Vector;
  26.  
  27. /**
  28.  * Instances of this class represent the name of a file or directory 
  29.  * on the host file system. A file is specified by a pathname, which 
  30.  * can either be an absolute pathname or a pathname relative to the 
  31.  * current working directory. The pathname must follow the naming 
  32.  * conventions of the host platform. 
  33.  * <p>
  34.  * The <code>File</code> class is intended to provide an abstraction 
  35.  * that deals with most of the machine dependent complexities of 
  36.  * files and pathnames in a machine-independent fashion. 
  37.  * <p>
  38.  * Note that whenever a filename or path is used it is
  39.  * assumed that the host's file naming conventions are used.
  40.  *
  41.  * @version 1.49, 05/04/97
  42.  * @author  Arthur van Hoff
  43.  * @author  Jonathan Payne
  44.  * @since   JDK1.0
  45.  */
  46. public
  47. class File implements java.io.Serializable {
  48.     /**
  49.      * The path of the file. The host's file separator is used.
  50.      */
  51.     private String path;
  52.  
  53.     /**
  54.      * The system-dependent path separator character. This field is 
  55.      * initialized to contain the value of the system property 
  56.      * <code>file.separator</code>. 
  57.      *
  58.      * @see     java.lang.System#getProperty(java.lang.String)
  59.      * @since   JDK1.0
  60.      */
  61.     public static final String separator = System.getProperty("file.separator");
  62.  
  63.     /**
  64.      * The system-dependent path separator string. This field is 
  65.      * initialized to contain the first character of the value of the 
  66.      * system property <code>file.separator</code>. This character 
  67.      * separates the directory and file components in a filename. 
  68.      *
  69.      * @see     java.lang.System#getProperty(java.lang.String)
  70.      * @since   JDK1.0
  71.      */
  72.     public static final char separatorChar = separator.charAt(0);
  73.     
  74.     /**
  75.      * The system-dependent path separator string. This field is 
  76.      * initialized to contain the value of the system property 
  77.      * <code>path.separator</code>. 
  78.      *
  79.      * @see     java.lang.System#getProperty(java.lang.String)
  80.      * @since   JDK1.0
  81.      */
  82.     public static final String pathSeparator = System.getProperty("path.separator");
  83.  
  84.     /**
  85.      * The system-dependent path separator character. This field is 
  86.      * initialized to contain the first character of the value of the 
  87.      * system property <code>path.separator</code>. This character is 
  88.      * often used to separate filenames in a sequence of files given as a 
  89.      * "path list".
  90.      *
  91.      * @see     java.lang.System#getProperty(java.lang.String)
  92.      * @since   JDK1.0
  93.      */
  94.     public static final char pathSeparatorChar = pathSeparator.charAt(0);
  95.     
  96.     /**
  97.      * Creates a <code>File</code> instance that represents the file 
  98.      * whose pathname is the given path argument. 
  99.      *
  100.      * @param      path   the file pathname.
  101.      * @exception  NullPointerException  if the file path is equal to
  102.      *               <code>null</code>.
  103.      * @see        java.io.File#getPath()
  104.      * @since      JDK1.0
  105.      */
  106.     public File(String path) {
  107.     if (path == null) {
  108.         throw new NullPointerException();
  109.     }
  110.     this.path = path;
  111.     }    
  112.  
  113.     /**
  114.      * Creates a <code>File</code> instance whose pathname is the 
  115.      * pathname of the specified directory, followed by the separator 
  116.      * character, followed by the <code>name</code> argument. 
  117.      *
  118.      * @param   path   the directory pathname.
  119.      * @param   name   the file pathname.
  120.      * @see     java.io.File#getPath()
  121.      * @see     java.io.File#separator
  122.      * @since   JDK1.0
  123.      */
  124.     public File(String path, String name) {
  125.     if (name == null) {
  126.         /* raise exception, per Java Language Spec
  127.          * 22.24.6 & 22.24.7
  128.          */
  129.         throw new NullPointerException();
  130.     }
  131.     if (path != null) {
  132.         if (path.endsWith(separator)) {
  133.         this.path = path + name;
  134.         } else {
  135.         this.path = path + separator + name;
  136.         } 
  137.     } else {
  138.         this.path = name;
  139.     }
  140.     }
  141.  
  142.     /**
  143.      * Creates a <code>File</code> instance that represents the file 
  144.      * with the specified name in the specified directory. 
  145.      * <p>
  146.      * If the directory argument is <code>null</code>, the resulting 
  147.      * <code>File</code> instance represents a file in the 
  148.      * (system-dependent) current directory whose pathname is the 
  149.      * <code>name</code> argument. Otherwise, the <code>File</code> 
  150.      * instance represents a file whose pathname is the pathname of the 
  151.      * directory, followed by the separator character, followed by the 
  152.      * <code>name</code> argument. 
  153.      *
  154.      * @param   dir   the directory.
  155.      * @param   name   the file pathname.
  156.      * @see     java.io.File#getPath()
  157.      * @see     java.io.File#separator
  158.      * @since   JDK1.0
  159.      */
  160.     public File(File dir, String name) {
  161.     this(dir.getPath(), name);
  162.     }
  163.  
  164.     /**
  165.      * Returns the name of the file represented by this object. The name 
  166.      * is everything in the pathame after the last occurrence of the 
  167.      * separator character. 
  168.      *
  169.      * @return  the name of the file (without any directory components)
  170.      *          represented by this <code>File</code> object.
  171.      * @see     java.io.File#getPath()
  172.      * @see     java.io.File#separator
  173.      * @since   JDK1.0
  174.      */
  175.     public String getName() {
  176.     int index = path.lastIndexOf(separatorChar);
  177.     return (index < 0) ? path : path.substring(index + 1);
  178.     }
  179.  
  180.     /**
  181.      * Returns the pathname of the file represented by this object.
  182.      *
  183.      * @return  the pathname represented by this <code>File</code> object.
  184.      * @since   JDK1.0
  185.      */
  186.     public String getPath() {
  187.     return path;
  188.     }
  189.  
  190.     /**
  191.      * Returns the absolute pathname of the file represented by this object.
  192.      * If this object represents an absolute pathname, then return the 
  193.      * pathname. Otherwise, return a pathname that is a concatenation of 
  194.      * the current user directory, the separator character, and the 
  195.      * pathname of this file object. 
  196.      * <p>
  197.      * The system property <code>user.dir</code> contains the current 
  198.      * user directory. 
  199.      *
  200.      * @return  a system-dependent absolute pathname for this <code>File</code>.
  201.      * @see     java.io.File#getPath()
  202.      * @see     java.io.File#isAbsolute()
  203.      * @see     java.lang.System#getProperty(java.lang.String)
  204.      * @since   JDK1.0
  205.      */
  206.     public String getAbsolutePath() {
  207.     return isAbsolute() ? path : System.getProperty("user.dir") + separator + path;
  208.     }
  209.  
  210.     /**
  211.      * Returns the canonical form of this <code>File</code> object's pathname.
  212.      * The precise definition of canonical form is system-dependent, but it
  213.      * usually specifies an absolute pathname in which all relative references
  214.      * and references to the current user directory have been completely
  215.      * resolved.  The canonical form of a pathname of a nonexistent file may
  216.      * not be defined.
  217.      *
  218.      * @exception IOException If an I/O error occurs, which is possible because
  219.      * the construction of the canonical path may require filesystem queries.
  220.      *
  221.      * @since   JDK1.1
  222.      */
  223.      public String getCanonicalPath() throws IOException {
  224.     return isAbsolute() ? canonPath(path) :
  225.         canonPath(System.getProperty("user.dir") + separator + path);
  226.     }
  227.  
  228.     /**
  229.      * Returns the parent part of the pathname of this <code>File</code>
  230.      * object, or <code>null</code> if the name has no parent part.  The parent
  231.      * part is generally everything leading up to the last occurrence of the
  232.      * separator character, although the precise definition is system
  233.      * dependent.  On UNIX, for example, the parent part of
  234.      * <code>"/usr/lib"</code> is <code>"/usr"</code>, whose parent part is
  235.      * <code>"/"</code>, which in turn has no parent.  On Windows platforms,
  236.      * the parent part of <code>"c:\java"</code> is <code>"c:\"</code>, which
  237.      * in turn has no parent.
  238.      *
  239.      * @see     java.io.File#getPath()
  240.      * @see     java.io.File#getCanonicalPath()
  241.      * @see     java.io.File#separator
  242.      * @since   JDK1.0
  243.      */
  244.     public String getParent() {
  245.     /* This is correct for Unix and Win32; other platforms may require a
  246.            different algorithm */
  247.     int index = path.lastIndexOf(separatorChar);
  248.     if (index < 0)
  249.         return null;
  250.     if (!isAbsolute() || (path.indexOf(separatorChar) != index))
  251.         return path.substring(0, index);
  252.     if (index < path.length() - 1)
  253.         return path.substring(0, index + 1);
  254.     return null;
  255.     }
  256.  
  257.     private native boolean exists0();
  258.     private native boolean canWrite0();
  259.     private native boolean canRead0();
  260.     private native boolean isFile0();
  261.     private native boolean isDirectory0();
  262.     private native long lastModified0();
  263.     private native long length0();
  264.     private native boolean mkdir0();
  265.     private native boolean renameTo0(File dest);
  266.     private native boolean delete0();
  267.     private native boolean rmdir0(); // remove empty directory
  268.     private native String[] list0();
  269.     private native String canonPath(String p) throws IOException;
  270.  
  271.     /**
  272.      * Tests if this <code>File</code> exists. 
  273.      *
  274.      * @return     <code>true</code> if the file specified by this object
  275.      *             exists; <code>false</code> otherwise.
  276.      * @exception  SecurityException  if a security manager exists, its
  277.      *               <code>checkRead</code> method is called with the pathname
  278.      *               of this <code>File</code> to see if the application is
  279.      *               allowed read access to the file.
  280.      * @see        java.io.File#getPath()
  281.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  282.      * @since      JDK1.0
  283.      */
  284.     public boolean exists() {
  285.     SecurityManager security = System.getSecurityManager();
  286.     if (security != null) {
  287.         security.checkRead(path);
  288.     }
  289.     return exists0();
  290.     }
  291.  
  292.     /**
  293.      * Tests if the application can write to this file. 
  294.      *
  295.      * @return     <code>true</code> if the application is allowed to write to
  296.      *             a file whose name is specified by this object;
  297.      *            <code>false</code> otherwise.
  298.      * @exception  SecurityException  if a security manager exists, its
  299.      *               <code>checkWrite</code> method is called with the pathname
  300.      *               of this <code>File</code> to see if the application is
  301.      *               allowed write access to the file.
  302.      * @see        java.io.File#getPath()
  303.      * @see        java.lang.SecurityManager#checkWrite(java.lang.String)
  304.      * @since      JDK1.0
  305.      */
  306.     public boolean canWrite() {
  307.     SecurityManager security = System.getSecurityManager();
  308.     if (security != null) {
  309.         security.checkWrite(path);
  310.     }
  311.     return canWrite0();
  312.     }
  313.  
  314.     /**
  315.      * Tests if the application can read from the specified file. 
  316.      *
  317.      * @return     <code>true</code> if the file specified by this object exists
  318.      *             and the application can read the file;
  319.      *             <code>false</code> otherwise.
  320.      * @exception  SecurityException  if a security manager exists, its
  321.      *               <code>checkRead</code> method is called with the pathname
  322.      *               of this <code>File</code> to see if the application is
  323.      *               allowed read access to the file.
  324.      * @see        java.io.File#getPath()
  325.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  326.      * @since      JDK1.0
  327.      */
  328.     public boolean canRead() {
  329.     SecurityManager security = System.getSecurityManager();
  330.     if (security != null) {
  331.         security.checkRead(path);
  332.     }
  333.     return canRead0();
  334.     }
  335.  
  336.     /**
  337.      * Tests if the file represented by this <code>File</code> 
  338.      * object is a "normal" file. 
  339.      * <p>
  340.      * A file is "normal" if it is not a directory and, in 
  341.      * addition, satisfies other system-dependent criteria. Any 
  342.      * non-directory file created by a Java application is guaranteed to 
  343.      * be a normal file. 
  344.      *
  345.      * @return     <code>true</code> if the file specified by this object
  346.      *             exists and is a "normal" file; <code>false</code> otherwise.
  347.      * @exception  SecurityException  If a security manager exists, its
  348.      *               <code>checkRead</code> method is called with the pathname
  349.      *               of this <code>File</code> to see if the application is
  350.      *               allowed read access to the file.
  351.      * @see        java.io.File#getPath()
  352.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  353.      * @since      JDK1.0
  354.      */
  355.     public boolean isFile() {
  356.     SecurityManager security = System.getSecurityManager();
  357.     if (security != null) {
  358.         security.checkRead(path);
  359.     }
  360.     return isFile0();
  361.     }
  362.  
  363.     /**
  364.      * Tests if the file represented by this <code>File</code> 
  365.      * object is a directory. 
  366.      *
  367.      * @return     <code>true</code> if this <code>File</code> exists and is a
  368.      *             directory; <code>false</code> otherwise.
  369.      * @exception  SecurityException  if a security manager exists, its
  370.      *               <code>checkRead</code> method is called with the pathname
  371.      *               of this <code>File</code> to see if the application is
  372.      *               allowed read access to the file.
  373.      * @see        java.io.File#getPath()
  374.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  375.      * @since      JDK1.0
  376.      */
  377.     public boolean isDirectory() {
  378.     SecurityManager security = System.getSecurityManager();
  379.     if (security != null) {
  380.         security.checkRead(path);
  381.     }
  382.     return isDirectory0();
  383.     }
  384.  
  385.     /**
  386.      * Tests if the file represented by this <code>File</code> object is an
  387.      * absolute pathname. The definition of an absolute pathname is system 
  388.      * dependent. For example, on UNIX, a pathname is absolute if its 
  389.      * first character is the separator character. On Windows platforms, 
  390.      * a pathname is absolute if its first character is an ASCII '\' or 
  391.      * '/', or if it begins with a letter followed by a colon. 
  392.      *
  393.      * @return  <code>true</code> if the pathname indicated by the
  394.      *          <code>File</code> object is an absolute pathname;
  395.      *          <code>false</code> otherwise.
  396.      * @see     java.io.File#getPath()
  397.      * @see     java.io.File#separator
  398.      * @since   JDK1.0
  399.      */
  400.     public native boolean isAbsolute();
  401.  
  402.     /**
  403.      * Returns the time that the file represented by this 
  404.      * <code>File</code> object was last modified. 
  405.      * <p>
  406.      * The return value is system dependent and should only be used to 
  407.      * compare with other values returned by last modified. It should not 
  408.      * be interpreted as an absolute time. 
  409.      *
  410.      * @return     the time the file specified by this object was last modified,
  411.      *             or <code>0L</code> if the specified file does not exist.
  412.      * @exception  SecurityException  if a security manager exists, its
  413.      *               <code>checkRead</code> method is called with the pathname
  414.      *               of this <code>File</code> to see if the application is
  415.      *               allowed read access to the file.
  416.      * @see        java.io.File#getPath()
  417.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  418.      * @since      JDK1.0
  419.      */
  420.     public long lastModified() {
  421.     SecurityManager security = System.getSecurityManager();
  422.     if (security != null) {
  423.         security.checkRead(path);
  424.     }
  425.     return lastModified0();
  426.     }
  427.  
  428.     /**
  429.      * Returns the length of the file represented by this 
  430.      * <code>File</code> object. 
  431.      *
  432.      * @return     the length, in bytes, of the file specified by this object,
  433.      *             or <code>0L</code> if the specified file does not exist.
  434.      * @exception  SecurityException  if a security manager exists, its
  435.      *               <code>checkRead</code> method is called with the pathname
  436.      *               of this <code>File</code> to see if the application is
  437.      *               allowed read access to the file.
  438.      * @see        java.io.File#getPath()
  439.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  440.      * @since      JDK1.0
  441.      */
  442.     public long length() {
  443.     SecurityManager security = System.getSecurityManager();
  444.     if (security != null) {
  445.         security.checkRead(path);
  446.     }
  447.     return length0();
  448.     }
  449.  
  450.     /**
  451.      * Creates a directory whose pathname is specified by this 
  452.      * <code>File</code> object. 
  453.      *
  454.      * @return     <code>true</code> if the directory could be created;
  455.      *             <code>false</code> otherwise.
  456.      * @exception  SecurityException  if a security manager exists, its
  457.      *               <code>checkWrite</code> method is called with the pathname
  458.      *               of this <code>File</code> to see if the application is
  459.      *               allowed write access to the file.
  460.      * @see        java.io.File#getPath()
  461.      * @see        java.lang.SecurityManager#checkWrite(java.lang.String)
  462.      * @since      JDK1.0
  463.      */
  464.     public boolean mkdir() {
  465.     SecurityManager security = System.getSecurityManager();
  466.     if (security != null) {
  467.         security.checkWrite(path);
  468.     }
  469.     return mkdir0();
  470.     }
  471.  
  472.     /**
  473.      * Renames the file specified by this <code>File</code> object to 
  474.      * have the pathname given by the <code>File</code> argument. 
  475.      *
  476.      * @param      dest   the new filename.
  477.      * @return     <code>true</code> if the renaming succeeds;
  478.      *             <code>false</code> otherwise.
  479.      * @exception  SecurityException  if a security manager exists, its
  480.      *               <code>checkWrite</code> method is called both with the
  481.      *               pathname of this file object and with the pathname of the
  482.      *               destination target object to see if the application is
  483.      *               allowed to write to both files.
  484.      * @see        java.io.File#getPath()
  485.      * @see        java.lang.SecurityManager#checkWrite(java.lang.String)
  486.      * @since      JDK1.0
  487.      */
  488.     public boolean renameTo(File dest) {
  489.     SecurityManager security = System.getSecurityManager();
  490.     if (security != null) {
  491.         security.checkWrite(path);
  492.         security.checkWrite(dest.path);
  493.     }
  494.     return renameTo0(dest);
  495.     }
  496.  
  497.     /**
  498.      * Creates a directory whose pathname is specified by this 
  499.      * <code>File</code> object, including any necessary parent directories.
  500.      *
  501.      * @return     <code>true</code> if the directory (or directories) could be
  502.      *             created; <code>false</code> otherwise.
  503.      * @exception  SecurityException  if a security manager exists, its
  504.      *               <code>checkWrite</code> method is called with the pathname
  505.      *               of each of the directories that is to be created, before
  506.      *               any of the directories are created.
  507.      * @see        java.io.File#getPath()
  508.      * @see        java.lang.SecurityManager#checkWrite(java.lang.String)
  509.      * @since      JDK1.0
  510.      */
  511.     public boolean mkdirs() {
  512.     if(exists()) {
  513.         return false;
  514.     }
  515.     if (mkdir()) {
  516.          return true;
  517.      }
  518.  
  519.     String parent = getParent();
  520.     return (parent != null) && (new File(parent).mkdirs() && mkdir());
  521.     }
  522.  
  523.     /**
  524.      * Returns a list of the files in the directory specified by this
  525.      * <code>File</code> object. 
  526.      *
  527.      * @return     an array of file names in the specified directory.
  528.      *             This list does not include the current directory or the
  529.      *             parent directory ("<code>.</code>" and "<code>..</code>"
  530.      *             on Unix systems).
  531.      * @exception  SecurityException  If a security manager exists, its
  532.      *               <code>checkRead</code> method is called with the pathname
  533.      *               of this <code>File</code> to see if the application is
  534.      *               allowed read access to the file.
  535.      * @see        java.io.File#getPath()
  536.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  537.      * @since      JDK1.0
  538.      */
  539.     public String[] list() {
  540.     SecurityManager security = System.getSecurityManager();
  541.     if (security != null) {
  542.         security.checkRead(path);
  543.     }
  544.     return list0();
  545.     }
  546.  
  547.     /**
  548.      * Returns a list of the files in the directory specified by this 
  549.      * <code>File</code> that satisfy the specified filter. 
  550.      *
  551.      * @param      filter   a filename filter.
  552.      * @return     an array of file names in the specified directory.
  553.      *             This list does not include the current directory or the
  554.      *             parent directory ("<code>.</code>" and "<code>..</code>"
  555.      *             on Unix systems).
  556.      * @exception  SecurityException  If a security manager exists, its
  557.      *               <code>checkRead</code> method is called with the pathname
  558.      *               of this <code>File</code> to see if the application is
  559.      *               allowed read access to the file.
  560.      * @see        java.io.File#getPath()
  561.      * @see        java.io.FilenameFilter
  562.      * @see        java.lang.SecurityManager#checkRead(java.lang.String)
  563.      * @since      JDK1.0
  564.      */
  565.     public String[] list(FilenameFilter filter) {
  566.     String names[] = list();
  567.  
  568.     if (names == null) {
  569.         return null;
  570.     }
  571.  
  572.     // Fill in the Vector
  573.     Vector v = new Vector();
  574.     for (int i = 0 ; i < names.length ; i++) {
  575.         if ((filter == null) || filter.accept(this, names[i])) {
  576.         v.addElement(names[i]);
  577.         }
  578.     }
  579.  
  580.     // Create the array
  581.     String files[] = new String[v.size()];
  582.     v.copyInto(files);
  583.  
  584.     return files;
  585.     }
  586.  
  587.     /**
  588.      * Deletes the file specified by this object.  If the target
  589.      * file to be deleted is a directory, it must be empty for deletion
  590.      * to succeed.
  591.      *
  592.      * @return     <code>true</code> if the file is successfully deleted;
  593.      *             <code>false</code> otherwise.
  594.      * @exception  SecurityException  if a security manager exists, its
  595.      *               <code>checkDelete</code> method is called with the
  596.      *               pathname of this <code>File</code> to see if the
  597.      *               application is allowed to delete the file.
  598.      * @see        java.io.File#getPath()
  599.      * @see        java.lang.SecurityManager#checkDelete(java.lang.String)
  600.      * @since      JDK1.0
  601.      */
  602.     public boolean delete() {
  603.     SecurityManager security = System.getSecurityManager();
  604.     if (security != null) {
  605.         security.checkDelete(path);
  606.     }
  607.     if(isDirectory())
  608.         return rmdir0();
  609.     else
  610.         return delete0();
  611.     }
  612.  
  613.     /**
  614.      * Computes a hashcode for the file.
  615.      *
  616.      * @return  a hash code value for this <code>File</code> object.
  617.      * @since   JDK1.0
  618.      */
  619.     public int hashCode() {
  620.     return path.hashCode() ^ 1234321;
  621.     }
  622.  
  623.     /**
  624.      * Compares this object against the specified object.
  625.      * Returns <code>true</code> if and only if the argument is 
  626.      * not <code>null</code> and is a <code>File</code> object whose 
  627.      * pathname is equal to the pathname of this object. 
  628.      *
  629.      * @param   obj   the object to compare with.
  630.      * @return  <code>true</code> if the objects are the same;
  631.      *          <code>false</code> otherwise.
  632.      * @since   JDK1.0
  633.      */
  634.     public boolean equals(Object obj) {
  635.     if ((obj != null) && (obj instanceof File)) {
  636.         return path.equals(((File)obj).path);
  637.     }
  638.     return false;
  639.     }
  640.  
  641.     /**
  642.      * Returns a string representation of this object. 
  643.      *
  644.      * @return  a string giving the pathname of this object. 
  645.      * @see     java.io.File#getPath()
  646.      * @since   JDK1.0
  647.      */
  648.     public String toString() {
  649.     return getPath();
  650.     }
  651.  
  652.     /**
  653.      * WriteObject is called to save this filename.
  654.      * The separator character is saved also so it can be replaced
  655.      * in case the path is reconstituted on a different host type.
  656.      */
  657.     private synchronized void writeObject(java.io.ObjectOutputStream s)
  658.         throws IOException
  659.     {
  660.     s.defaultWriteObject();
  661.     s.writeChar(separatorChar); // Add the separator character
  662.     }
  663.  
  664.     /**
  665.      * readObject is called to restore this filename.
  666.      * The original separator character is read.  If it is different
  667.      * than the separator character on this system. The old seperator
  668.      * is replaced by the current separator.
  669.      */
  670.     private synchronized void readObject(java.io.ObjectInputStream s)
  671.          throws IOException, ClassNotFoundException
  672.     {
  673.     s.defaultReadObject();
  674.     char sep = s.readChar(); // read the previous seperator char
  675.     if (sep != separatorChar)
  676.         path = path.replace(sep, separatorChar);
  677.     }
  678.  
  679.     /** use serialVersionUID from JDK 1.0.2 for interoperability */
  680.     private static final long serialVersionUID = 301077366599181567L;
  681. }
  682.