Servertec
Foundation Classes
1.3.3 09/04/2005

stec.sfc.Win32
Class FileSystem

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

public final class FileSystem
extends java.lang.Object

Used to copy and rename files, to get the path of the system's temporary directory, to get the name of a temporary file, to create temporary files, to retrieve an array containing drives paths and to get and set the current directory.

Since:
1.0.0 01/07/2001

Field Summary
static java.lang.String pathSeparator
          The String containing the character used to separate Win32 paths.
static char pathSeparatorChar
          The character used to separate Win32 paths.
static java.lang.String separator
          The String containing the character used to separate Win32 path elements.
static char separatorChar
          The character used to separate Win32 path elements.
 
Constructor Summary
FileSystem()
           
 
Method Summary
static void copy(java.lang.String source_filename, java.lang.String destination_filename, boolean overwrite)
          Used to copy the specified file to the given file path.
static void createDirectory(java.lang.String path)
          Creates the specified new directory.
static File createTempFile(File directory, java.lang.String prefix)
          Returns a File object for the constructed temporary file.
static File createTempFile(java.lang.String prefix)
          Returns a File object for the constructed temporary file in the system's temporary directory.
static File createTempFile(java.lang.String path, java.lang.String prefix)
          Returns a File object for the constructed temporary file.
static void delete(java.lang.String source_filename)
          Used to remove the specified file.
static java.lang.String[] drives()
          Returns an array of Strings containing all known drive paths.
static java.lang.String getCurrentDirectory()
          Returns the current directory.
static java.lang.String getSystemDirectory()
          Returns path for the system's Windows system directory.
static java.lang.String getTempFileName(java.lang.String directory, java.lang.String prefix, int unique)
          Returns path to temporary file.
static java.lang.String getTempPath()
          Returns path for the system's temporary directory.
static java.lang.String getWindowsDirectory()
          Returns path for the system's Windows directory.
static void move(java.lang.String source_filename, java.lang.String destination_filename, int move_mode)
          Used to move an existing file or directory.
static void removeDirectory(java.lang.String path)
          Deletes the specified directory.
static void rename(java.lang.String source_filename, java.lang.String destination_filename, boolean overwrite)
          Used to rename the specified file to the given file path.
static void setCurrentDirectory(java.lang.String path)
          Used to set the current directory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pathSeparatorChar

public static final char pathSeparatorChar
The character used to separate Win32 paths.

Win32 platforms use ;, semi-colon.

See Also:
Constant Field Values

pathSeparator

public static final java.lang.String pathSeparator
The String containing the character used to separate Win32 paths.

Win32 platforms use ;, semi-colon.


separatorChar

public static final char separatorChar
The character used to separate Win32 path elements.

Win32 platforms use \, back-slash.

See Also:
Constant Field Values

separator

public static final java.lang.String separator
The String containing the character used to separate Win32 path elements.

Win32 platforms use \, back-slash.

Constructor Detail

FileSystem

public FileSystem()
Method Detail

drives

public static final java.lang.String[] drives()
                                       throws Win32Exception
Returns an array of Strings containing all known drive paths.

Returns:
the String array containing all known drive paths.
Throws:
Win32Exception - if any error occurs.

getCurrentDirectory

public static final java.lang.String getCurrentDirectory()
                                                  throws Win32Exception
Returns the current directory.

Returns:
the current directory.
Throws:
Win32Exception - if any error occurs.

setCurrentDirectory

public static final void setCurrentDirectory(java.lang.String path)
                                      throws Win32Exception
Used to set the current directory.

Parameters:
path - a directory path.
Throws:
Win32Exception - if any error occurs.

copy

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

Parameters:
source_filename - the path to the file to copy.
destination_filename - the path to the new file.
overwrite - whether to overwrite any existing file.
Throws:
Win32Exception - if the destination file exists and overwrite is false or if any error occurs.

rename

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

Parameters:
source_filename - the path to the file to rename.
destination_filename - the new file path.
overwrite - whether to overwrite any existing file.
Throws:
Win32Exception - if the destination file exists and overwrite is false or if any error occurs.

move

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

If move_mode is DELAY_UNTIL_REBOOT then the source file cannot be read-only.

If the move_mode is DELAY_UNTIL_REBOOT and the destination is null then the source file will be deleted.

DELAY_UNTIL_REBOOT cannot be used with COPY.

REPLACE_EXISTING cannot be used if the destination is a directory

If the source file is a directory then the destination must be on the same drive.

If the destination file is on another drive then the move_mode must be set to COPY_ALLOWED.

Parameters:
source_filename - the path to the file or directory to move.
destination_filename - the new path.
move_mode - specifies how the source will be moved. Defined in FileMoveMode
Throws:
Win32Exception - if the destination file exists and REPLACE_EXISTING was not specified or if any error occurs.
Since:
1.2.0 12/03/2002

delete

public static final void delete(java.lang.String source_filename)
                         throws Win32Exception
Used to remove the specified file.

Parameters:
source_filename - the path to the file to delete.
Throws:
Win32Exception - if the file does not exist or if any error occurs.

getTempPath

public static final java.lang.String getTempPath()
                                          throws Win32Exception
Returns path for the system's temporary directory.

Returns:
path to the system's temporary directory.
Throws:
Win32Exception - if any error occurs.

getWindowsDirectory

public static final java.lang.String getWindowsDirectory()
                                                  throws Win32Exception
Returns path for the system's Windows directory.

Returns:
path to the system's Windows directory.
Throws:
Win32Exception - if any error occurs.

getSystemDirectory

public static final java.lang.String getSystemDirectory()
                                                 throws Win32Exception
Returns path for the system's Windows system directory.

Returns:
path to the system's Windows system directory.
Throws:
Win32Exception - if any error occurs.

getTempFileName

public static final java.lang.String getTempFileName(java.lang.String directory,
                                                     java.lang.String prefix,
                                                     int unique)
                                              throws Win32Exception
Returns path to temporary file.

Parameters:
directory - the directory path for the file.
prefix - the three (3) characters used to start the file name.
unique - a unique number to use in the file name.

The number is converted into a four (4) character hexadecimal value.

If 0 is used then the current system time will be used.

Returns:
path to the temporary file.
Throws:
Win32Exception - if any error occurs.

createTempFile

public static final File createTempFile(File directory,
                                        java.lang.String prefix)
                                 throws Win32Exception
Returns a File object for the constructed temporary file.

Temporarary files are not automatically deleted.

Parameters:
directory - the directory path for the file.
prefix - the three (3) characters used to start the file name.
Returns:
the File object to temporary file.
Throws:
Win32Exception - if any error occurs.

createTempFile

public static final File createTempFile(java.lang.String path,
                                        java.lang.String prefix)
                                 throws Win32Exception
Returns a File object for the constructed temporary file.

Temporarary files are not automatically deleted.

Parameters:
path - the directory path for the file.
prefix - the three (3) characters used to start the file name.
Returns:
the File object to temporary file.
Throws:
Win32Exception - if any error occurs.

createTempFile

public static final File createTempFile(java.lang.String prefix)
                                 throws Win32Exception
Returns a File object for the constructed temporary file in the system's temporary directory.

Temporarary files are not automatically deleted.

Parameters:
prefix - the three (3) characters used to start the file name.
Returns:
the File object to temporary file.
Throws:
Win32Exception - if any error occurs.

createDirectory

public static final void createDirectory(java.lang.String path)
                                  throws Win32Exception
Creates the specified new directory.

Parameters:
path - the mew directory to create.
Throws:
Win32Exception - if the specified directory cannot be created or if any error occurs.
Since:
1.2.0 12/03/2002

removeDirectory

public static final void removeDirectory(java.lang.String path)
                                  throws Win32Exception
Deletes the specified directory.

Parameters:
path - the directory to delete.
Throws:
Win32Exception - if the specified directory cannot be deleted or if any error occurs.
Since:
1.2.0 12/03/2002

Servertec
Foundation Classes
1.3.3 09/04/2005

Copyright © 2001-2005 Servertec. All rights reserved.