Servertec
Foundation Classes
1.3.3 09/04/2005

stec.sfc.Win32
Class File

java.lang.Object
  extended by stec.sfc.Win32.File

public final class File
extends java.lang.Object

Used to copy, rename, delete a file or directory, retrieve a file's or directory's short and long path names, get and set a file's or directory's attributes, last modified time, last accessed time and created time.

Since:
1.0.0 01/07/2001

Constructor Summary
File(java.lang.String path)
          Constructs a new File object.
 
Method Summary
 void copy(java.lang.String destination_filename, boolean overwrite)
          Used to copy the file to the specified file path.
 void delete()
          Delete the file.
 boolean exists()
          Returns whether the file or directory exists.
 int getAttributes()
          Returns the file's or directory's attributes.
 long getCompressedLength()
          Returns the compressed file's size in bytes.
 long getCreationTime()
          Returns the file's or directory's creation time in the number of 100-nanosecond intervals since January 1, 1601.
 long getCreationTimeEx()
          Returns the file's or directory's creation time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
 long getID()
          Returns the file's or directory's unique identifier.
 long getLastAccessedTime()
          Returns the file's or directory's last accessed time in the number of 100-nanosecond intervals since January 1, 1601.
 long getLastAccessedTimeEx()
          Returns the file's or directory's last accessed time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
 long getLastModifiedTime()
          Returns the file's or directory's last modified time in the number of 100-nanosecond intervals since January 1, 1601.
 long getLastModifiedTimeEx()
          Returns the file's or directory's last modified time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
 java.lang.String getLongPathName()
          Returns the file's or directory's long path name from the MS-DOS short path name.
 java.lang.String getShortPathName()
          Returns the file's or directory's MS-DOS short path name.
 int getType()
          Returns the file's or directory's type as defined in FileType.
 int getVolumeSerialNumber()
          Returns the serial number of the volume that contains the file or directory.
static long java2native(long timestamp)
          Returns the native timestamp for the specified Java timestamp.
 long length()
          Returns the file's size in bytes.
 void move(java.lang.String destination_filename, int move_mode)
          Used to move the existing file or directory.
static long native2java(long timestamp)
          Returns the Java timestamp for the specified native timestamp.
 void rename(java.lang.String destination_filename, boolean overwrite)
          Used to rename the file to the specified file path.
 void setAttributes(int attributes)
          Used to set the file's or directory's attributes.
 void setCreationTime(long timestamp)
          Used to set the file's or directory's creation time in the number of 100-nanosecond intervals since January 1, 1601.
 void setCreationTimeEx(long timestamp)
          Used to set the file's or directory's creation time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
 void setLastAccessedTime(long timestamp)
          Used to set the file's or directory's last accessed time in the number of 100-nanosecond intervals since January 1, 1601.
 void setLastAccessedTimeEx(long timestamp)
          Used to set the file's or directory's last accessed time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
 void setLastModifiedTime(long timestamp)
          Used to set the file's or directory's last modified time in the number of 100-nanosecond intervals since January 1, 1601.
 void setLastModifiedTimeEx(long timestamp)
          Used to set the file's or directory's last modified time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
 java.lang.String toString()
          Returns the file's or directory's path.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

File

public File(java.lang.String path)
Constructs a new File object.

Parameters:
path - the path to the file or directory.
Method Detail

getShortPathName

public final java.lang.String getShortPathName()
                                        throws Win32Exception
Returns the file's or directory's MS-DOS short path name.

This method does not expand the file's or directory's path.

Returns:
the file's or directory's short path name.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.

getLongPathName

public final java.lang.String getLongPathName()
                                       throws Win32Exception
Returns the file's or directory's long path name from the MS-DOS short path name.

This method does not expand the file's or directory's path.

Not supported on Windows NT.

Returns:
the file's or directory's long path name. On Windows NT will return null.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.

getAttributes

public final int getAttributes()
                        throws Win32Exception
Returns the file's or directory's attributes.

Returns:
the file's or directory's attributes.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
See Also:
FileAttribute

setAttributes

public final void setAttributes(int attributes)
                         throws Win32Exception
Used to set the file's or directory's attributes.

Parameters:
attributes - the file's or directory's attributes.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.

toString

public final java.lang.String toString()
Returns the file's or directory's path.

Overrides:
toString in class java.lang.Object
Returns:
the file's or directory's path.

delete

public final void delete()
                  throws Win32Exception
Delete the file.

Throws:
Win32Exception - if the file does not exist or if any errors occur.

copy

public final void copy(java.lang.String destination_filename,
                       boolean overwrite)
                throws Win32Exception
Used to copy the file to the specified file path.

Parameters:
destination_filename - the path to the new file.
overwrite - whether to overwrite any existing file.
Throws:
Win32Exception - if the file does not exist or if the destination file exists and overwrite is false or if any errors occur.

rename

public final void rename(java.lang.String destination_filename,
                         boolean overwrite)
                  throws Win32Exception
Used to rename the file to the specified file path.

Parameters:
destination_filename - the new file path.
overwrite - whether to overwrite any existing file.
Throws:
Win32Exception - if the file does not exist or if the destination file exists and overwrite is false or if any errors occur.

move

public final void move(java.lang.String destination_filename,
                       int move_mode)
                throws Win32Exception
Used to move the existing file or directory.

Parameters:
destination_filename - the new path.
move_mode - specifies how the source will be moved. Defined in FileMoveMode
Throws:
Win32Exception - if the file does not exist or if the destination file exists and REPLACE_EXISTING was not specified or if any errors occur.
Since:
1.2.0 12/03/2002

exists

public final boolean exists()
                     throws Win32Exception
Returns whether the file or directory exists.

Returns:
whether the file or directory exists.
Throws:
Win32Exception - if any errors occur.

getCreationTime

public final long getCreationTime()
                           throws Win32Exception
Returns the file's or directory's creation time in the number of 100-nanosecond intervals since January 1, 1601. The creation time recorded resolution is platform dependant.

Returns:
the file's or directory's creation time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.2.0 12/03/2002

getCreationTimeEx

public final long getCreationTimeEx()
                             throws Win32Exception
Returns the file's or directory's creation time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. The creation time recorded resolution is platform dependant.

Returns:
the file's or directory's creation time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.2.0 12/03/2002

getLastModifiedTime

public final long getLastModifiedTime()
                               throws Win32Exception
Returns the file's or directory's last modified time in the number of 100-nanosecond intervals since January 1, 1601. The last access time recorded resolution is platform dependant.

Returns:
the file's or directory's last modified time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.

getLastModifiedTimeEx

public final long getLastModifiedTimeEx()
                                 throws Win32Exception
Returns the file's or directory's last modified time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. The last access time recorded resolution is platform dependant.

Returns:
the file's or directory's last modified time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.1.0 11/18/2001

getLastAccessedTime

public final long getLastAccessedTime()
                               throws Win32Exception
Returns the file's or directory's last accessed time in the number of 100-nanosecond intervals since January 1, 1601. The last accessed time recorded resolution is platform dependant.

Returns:
the file's or directory's last accessed time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.2.0 12/03/2002

getLastAccessedTimeEx

public final long getLastAccessedTimeEx()
                                 throws Win32Exception
Returns the file's or directory's last accessed time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. The last accessed time recorded resolution is platform dependant.

Returns:
the file's or directory's last accessed time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.2.0 12/03/2002

setCreationTime

public final void setCreationTime(long timestamp)
                           throws Win32Exception
Used to set the file's or directory's creation time in the number of 100-nanosecond intervals since January 1, 1601. The creation time recorded resolution is platform dependant.

Parameters:
timestamp - the file's or directory's creation time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.

setCreationTimeEx

public final void setCreationTimeEx(long timestamp)
                             throws Win32Exception
Used to set the file's or directory's creation time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. The creation time recorded resolution is platform dependant.

Parameters:
timestamp - the file's or directory's creation time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.1.0 11/18/2001

setLastModifiedTime

public final void setLastModifiedTime(long timestamp)
                               throws Win32Exception
Used to set the file's or directory's last modified time in the number of 100-nanosecond intervals since January 1, 1601. The last modified time recorded resolution is platform dependant.

Parameters:
timestamp - the file's or directory's last modified time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.

setLastModifiedTimeEx

public final void setLastModifiedTimeEx(long timestamp)
                                 throws Win32Exception
Used to set the file's or directory's last modified time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. The last modified time recorded resolution is platform dependant.

Parameters:
timestamp - the file's or directory's last modified time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.1.0 11/18/2001

setLastAccessedTime

public final void setLastAccessedTime(long timestamp)
                               throws Win32Exception
Used to set the file's or directory's last accessed time in the number of 100-nanosecond intervals since January 1, 1601. The last accessed time recorded resolution is platform dependant.

Parameters:
timestamp - the file's or directory's last accessed time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.

setLastAccessedTimeEx

public final void setLastAccessedTimeEx(long timestamp)
                                 throws Win32Exception
Used to set the file's or directory's last accessed time in the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. The last accessed time recorded resolution is platform dependant.

Parameters:
timestamp - the file's or directory's last accessed time.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.1.0 11/18/2001

native2java

public static final long native2java(long timestamp)
Returns the Java timestamp for the specified native timestamp.

Parameters:
timestamp - the native timestamp.
Returns:
the Java timestamp.
Since:
1.2.0 12/03/2002

java2native

public static final long java2native(long timestamp)
Returns the native timestamp for the specified Java timestamp.

Parameters:
timestamp - the Java timestamp.
Returns:
the native timestamp.
Since:
1.2.0 12/03/2002

getType

public final int getType()
                  throws Win32Exception
Returns the file's or directory's type as defined in FileType.

Returns:
the file's or directory's type.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.2.0 12/03/2002

length

public final long length()
                  throws Win32Exception
Returns the file's size in bytes.

Returns:
the file's size in bytes. Always returns 0 for a directory.
Throws:
Win32Exception - if the file does not exist, if the file is a directory or if any errors occur.
Since:
1.2.0 12/03/2002

getCompressedLength

public final long getCompressedLength()
                               throws Win32Exception
Returns the compressed file's size in bytes.

Not supported on Windows 9x and Windows Me.

Returns:
the compressed file's size in bytes. Always returns 0 for a directory. On Windows 9x and Windows Me will return -1.
Throws:
Win32Exception - if the file does not exist, if the file is a directory or if any errors occur.
Since:
1.2.0 12/03/2002

getVolumeSerialNumber

public final int getVolumeSerialNumber()
                                throws Win32Exception
Returns the serial number of the volume that contains the file or directory.

When combined getVolumeSerialNumber() and getID() provide a unique identifier for the file or directory on this system.

Returns:
the serial number of the volume that contains the file or directory.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.2.0 12/03/2002

getID

public final long getID()
                 throws Win32Exception
Returns the file's or directory's unique identifier.

When combined getVolumeSerialNumber() and getID() provide a unique identifier for the file or directory on this system.

Returns:
the file's or directory's unique identifier.
Throws:
Win32Exception - if the file or directory does not exist or if any errors occur.
Since:
1.2.0 12/03/2002

Servertec
Foundation Classes
1.3.3 09/04/2005

Copyright © 2001-2005 Servertec. All rights reserved.