home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / doc / file.jav < prev    next >
Encoding:
Text File  |  1996-02-26  |  2.4 KB  |  74 lines

  1. /*
  2.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. /*
  18.  * The File class defined here is loosely based on the File classes
  19.  * provided as part of the Java base io classes. This File class is
  20.  * an abstract superclass that provides basic file and path manipulation
  21.  * with the expectation that subclasses will provide the actual file
  22.  * management code depending on the file semantics they want to present.
  23.  * For example, read-only input files and read and write output files.
  24.  */
  25.  
  26. /**
  27.  * The File superclass defines an interface for manipulating path
  28.  * and file names.  
  29.  *
  30.  */
  31. public
  32. class File {
  33.  
  34.     /**
  35.      * The file path.
  36.      */
  37.     protected String path;
  38.  
  39.     /**
  40.      * The class File's notion of a path separator character. This
  41.      * will be the Java path separator. Note that this will be
  42.      * converted to the system dependent path separator at runtime
  43.      * by code in the native library.
  44.      */
  45.     public static final char separatorChar = ':';
  46.  
  47.     /**
  48.      * The constructor initializes the class with the given path. Note
  49.      * that we use the String class found in the Java core classes.
  50.      *
  51.      */
  52.     public File(String path) {
  53.     if (path == null) {
  54.         throw new NullPointerException();
  55.     }
  56.     this.path = path;
  57.     }    
  58.  
  59.     /**
  60.      * Get the name of the file, not including the directory path.
  61.      */
  62.     public String getFileName() {
  63.     int index = path.lastIndexOf(separatorChar);
  64.     return (index < 0) ? path : path.substring(index + 1);
  65.     }
  66.  
  67.     /**
  68.      * Get the name of the file including the full directory path.
  69.      */
  70.     public String getPath() {
  71.     return path;
  72.     }
  73. }
  74.