Class TextFile

  • All Implemented Interfaces:
    Serializable, Comparable<File>

    public class TextFile
    extends File
    Utility class to handle text files as a single lump of text.

    Note this is just as memory-inefficient as handling a text file can be. Use with restraint.

    Version:
    $Revision: 1639469 $
    See Also:
    Serialized Form
    • Constructor Detail

      • TextFile

        public TextFile​(File filename,
                        String encoding)
        Create a TextFile object to handle the named file with the given encoding.
        Parameters:
        filename - File to be read and written through this object.
        encoding - Encoding to be used when reading and writing this file.
      • TextFile

        public TextFile​(File filename)
        Create a TextFile object to handle the named file with the platform default encoding.
        Parameters:
        filename - File to be read and written through this object.
      • TextFile

        public TextFile​(String filename)
        Create a TextFile object to handle the named file with the platform default encoding.
        Parameters:
        filename - Name of the file to be read and written through this object.
      • TextFile

        public TextFile​(String filename,
                        String encoding)
        Create a TextFile object to handle the named file with the given encoding.
        Parameters:
        filename - Name of the file to be read and written through this object.
        encoding - Encoding to be used when reading and writing this file.
    • Method Detail

      • setText

        public void setText​(String body)
        Create the file with the given string as content -- or replace it's content with the given string if the file already existed.
        Parameters:
        body - New content for the file.
      • getText

        public String getText()
        Read the whole file content and return it as a string.
        Returns:
        the content of the file
      • getEncoding

        public String getEncoding()
        Returns:
        Encoding being used to read and write this file.
      • setEncoding

        public void setEncoding​(String string)
        Parameters:
        string - Encoding to be used to read and write this file.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class File
      • equals

        public boolean equals​(Object obj)
        Overrides:
        equals in class File