de.goerntkai.toolbox.fs
Class File

java.lang.Object
  extended byjava.io.File
      extended byde.goerntkai.toolbox.fs.File
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
Folder

public class File
extends java.io.File

Represents a file object in the file system. The base java.io.File is extended with copyTo which copies the file to the given destination.

Version:
$Id: File.java,v 1.3 2007/05/06 16:25:51 GoerntKai Exp $
Author:
Kai Görnt
See Also:
File, Serialized Form

Field Summary
static java.lang.String SUFFIX_SEPERATOR
          Seperates the bare name from the suffix.
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
File(java.io.File theFile)
          Creates a new File from an object of its superclass.
File(java.io.File theParent, java.lang.String theChild)
          Inherited from java.io.File.
File(java.lang.String thePathname)
          Inherited from java.io.File.
File(java.lang.String theParent, java.lang.String theChild)
          Inherited from java.io.File.
File(java.net.URI theURI)
          Inherited from java.io.File.
 
Method Summary
 long copyTo(File destination)
          Copies this file object to the given destination file.
 long copyTo(java.lang.String destinationFile)
          Copies this file object to the given destination file.
 java.lang.String getBareName()
          Returns the bare name of the file name.
 java.lang.String getSuffix()
          Returns the suffix of the file name.
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SUFFIX_SEPERATOR

public static final java.lang.String SUFFIX_SEPERATOR
Seperates the bare name from the suffix. Will be the same for all OS.

See Also:
Constant Field Values
Constructor Detail

File

public File(java.io.File theFile)

Creates a new File from an object of its superclass.

Parameters:
theFile - to create

File

public File(java.io.File theParent,
            java.lang.String theChild)

Inherited from java.io.File.

Parameters:
theParent - to create the child in
theChild - to create
See Also:
File

File

public File(java.lang.String thePathname)

Inherited from java.io.File.

Parameters:
thePathname - of the file
See Also:
File

File

public File(java.lang.String theParent,
            java.lang.String theChild)

Inherited from java.io.File.

Parameters:
theParent - to create the child in
theChild - to create
See Also:
File

File

public File(java.net.URI theURI)

Inherited from java.io.File.

Parameters:
theURI - of the file
See Also:
File
Method Detail

copyTo

public final long copyTo(File destination)
                  throws java.io.IOException

Copies this file object to the given destination file. Copies only files, no directories. Uses FileInputStream for the source and FileOutputStream for the destination. The copy will take byte for byte. Returns the number of bytes that were copied. Returns -1 if the source was no file. Any existing file will be overwritten.

In case that parent directories of the destination files are missing this method will create them.

Parameters:
destination - the destination file
Returns:
the number of bytes that were copied
Throws:
java.io.IOException - on problems with the streams

copyTo

public final long copyTo(java.lang.String destinationFile)
                  throws java.io.IOException

Copies this file object to the given destination file. Just calls copyTo(File) with the File created from destinationFile.

Parameters:
destinationFile - where to copy the file to
Returns:
the number of bytes that were copied
Throws:
java.io.IOException - on problems with the streams
See Also:
copyTo(File)

getBareName

public final java.lang.String getBareName()

Returns the bare name of the file name. The last dot is the splitting element. The bare name is the part left to the last dot. For example, the file name is file-0.1.txt the bare name will be file-0.1.

Returns:
the bare name

getSuffix

public final java.lang.String getSuffix()

Returns the suffix of the file name. The last dot is the splitting element. The suffix is the part right to the last dot. For example, the file name is file-0.1.txt the suffix will be txt.

Returns:
the file name suffix


Copyright © 2004-2007 Kai Görnt. All Rights Reserved.