|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.File | +--sdsu.io.SimpleFile
This class adds a few useful methods to java.io.File. This class provides methods to backup a file, to read the contents of a file, and write to a file. These methods are very simple, but are done so often it becomes annoying to implement each time they are needed.
Fields inherited from class java.io.File |
pathSeparator,
pathSeparatorChar,
separator,
separatorChar |
Constructor Summary | |
SimpleFile(java.io.File dir,
java.lang.String name)
Creates a File instance that represents the file
with the specified name in the specified directory. |
|
SimpleFile(java.lang.String path)
Creates a File instance that represents the file
whose pathname is the given path argument. |
|
SimpleFile(java.lang.String path,
java.lang.String name)
Creates a File instance whose pathname is the
pathname of the specified directory, followed by the separator
character, followed by the name argument. |
Method Summary | |
void |
append(java.lang.String tailContents)
Appends the string tailContents to the end of the file. |
void |
backup()
Create a backup copy of the current file. |
void |
backup(java.lang.String fileExtension)
Create a backup copy of the current file. |
java.lang.String |
getContents()
Returns the contents of the file. |
void |
setContents(java.lang.String newContents)
Set the contents of the file to be newContents to the end of the file. |
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,
toURL |
Methods inherited from class java.lang.Object |
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public SimpleFile(java.lang.String path)
File
instance that represents the file
whose pathname is the given path argument.path
- the file pathname.null
.File.getPath()
public SimpleFile(java.lang.String path, java.lang.String name)
File
instance whose pathname is the
pathname of the specified directory, followed by the separator
character, followed by the name
argument.path
- the directory pathname.name
- the file pathname.File.getPath()
,
File.separator
public SimpleFile(java.io.File dir, java.lang.String name)
File
instance that represents the file
with the specified name in the specified directory.
If the directory argument is null
, the resulting
File
instance represents a file in the
(system-dependent) current directory whose pathname is the
name
argument. Otherwise, the File
instance represents a file whose pathname is the pathname of the
directory, followed by the separator character, followed by the
name
argument.
dir
- the directory.name
- the file pathname.File.getPath()
,
File.separator
Method Detail |
public java.lang.String getContents() throws java.io.FileNotFoundException, java.io.IOException
This is a very simple function, but is done often enough to have done for you. It also allows beginners to read files before having to master Readers/Writers.
public void append(java.lang.String tailContents) throws java.io.IOException
tailContents
- String added to the end of the file.public void setContents(java.lang.String newContents) throws java.io.IOException
newContents
- String used to replace current contents of the file.public void backup() throws java.io.IOException
public void backup(java.lang.String fileExtension) throws java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |