Class TextFile

java.lang.Object
  extended byTextFile

public class TextFile
extends Object

A TextFile mimics the sort of text file that one finds on a computer's file system. It has an owner, a create date (when the file was created), a modification date (when the file was last modified), and String contents.

Version:
3

Constructor Summary
TextFile(String owner, String contents)
          Construct a new TextFile with given owner and contents; set the creation and modification dates.
 
Method Summary
 void append(String text)
          Append text to the end of the file.
 void appendLine(String text)
          Append a new line of text to the end of the file.
 String getContents()
          The contents of a file.
 String getCreateDate()
          The data and time of the file's creation.
 String getModDate()
          The date and time of the file's last modification.
 String getOwner()
          The file's owner.
 int getSize()
          The size of a file.
static void main(String[] args)
          A definition of main(), used only for testing this class.
 void setContents(String contents)
          Replace the contents of the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextFile

public TextFile(String owner,
                String contents)
Construct a new TextFile with given owner and contents; set the creation and modification dates.

Parameters:
owner - the user who owns the file.
contents - the file's initial contents.
Method Detail

append

public void append(String text)
Append text to the end of the file.

Parameters:
text - the text to be appended.

appendLine

public void appendLine(String text)
Append a new line of text to the end of the file.

Parameters:
text - the text to be appended.

getContents

public String getContents()
The contents of a file.

Returns:
String contents of the file.

getCreateDate

public String getCreateDate()
The data and time of the file's creation.

Returns:
the file's creation date and time.

getModDate

public String getModDate()
The date and time of the file's last modification.

Returns:
the date and time of the file's last modification.

getOwner

public String getOwner()
The file's owner.

Returns:
the owner of the file.

getSize

public int getSize()
The size of a file.

Returns:
the integer size of the file (the number of characters in its String contents)

main

public static void main(String[] args)
A definition of main(), used only for testing this class. Executing
     %> java TextFile
 
produces the output:
 TextFile myTextFile contains 13 characters.
 Created by bill, Sat Dec 29 14:02:37 EST 2001
 Hello, world.

 append new line "How are you today?"
 Hello, world.
 How are you today?
 TextFile myTextFile contains 32 characters.
 Modified Sat Dec 29 14:02:38 EST 2001
 


setContents

public void setContents(String contents)
Replace the contents of the file.

Parameters:
contents - the new contents.