Package hsafx

Class TextOutputFile


  • public class TextOutputFile
    extends Object
    The TextOutputFile writes text to a file. The class is a superset of PrintWriter adding formatted output and integrated error checking.
    Version:
    6.0 May 2018
    Author:
    Sam Scott (code cleanup for version 5.0), Tom West
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean closed
      Set if the file has been closed.
      protected PrintWriter f
      Streams used for the file
      protected String fileName
      The file name.
      protected String lineSeparator
      The line separator in files
      protected boolean useStandardIO
      Indicator whether to write to standard output or a file.
    • Constructor Summary

      Constructors 
      Constructor Description
      TextOutputFile()
      Contructor - TextOutputFile to write to standard output.
      TextOutputFile​(File file)
      Contructor - TextOutputFile to write to a File.
      TextOutputFile​(File file, boolean append)
      Contructor - TextOutputFile to write or append to a File.
      TextOutputFile​(String fileName)
      Contructor - TextFile to write to file with specified name.
      TextOutputFile​(String fileName, boolean append)
      Contructor - TextFile to write or append to file with specified name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the file to further writing.
      boolean isStandardOut()  
      void print​(boolean value)
      Write the text representation of a boolean to the file.
      void print​(boolean value, int fieldSize)
      Write the text representation of a boolean to the file with a specified field size.
      void print​(byte number)
      Write the text representation of an 8-bit integer (a "byte") to the file.
      void print​(byte number, int fieldSize)
      Write the text representation of an 8-bit integer (a "byte") to the file with a specified field size.
      void print​(char ch)
      Write a character to the file.
      void print​(char ch, int fieldSize)
      Write a character to the file with a specified field size..
      void print​(double number)
      Write a double precision floating point number (a "double") to the file.
      void print​(double number, int fieldSize)
      Write a double precision floating point number (a "double") to the file with a specified field size.
      void print​(double number, int fieldSize, int decimalPlaces)
      Write a double precision floating point number (a "double") to the file with a specified field size and a specified number of decimal places.
      void print​(float number)
      Write a floating point number (a "float") to the file.
      void print​(float number, int fieldSize)
      Write a floating point number (a "float") to the file with a specified field size.
      void print​(float number, int fieldSize, int decimalPlaces)
      Write a floating point number (a "double") to the file with a specified field size and a specified number of decimal places.
      void print​(int number)
      Write the text representation of an 32-bit integer (an "int") to the file.
      void print​(int number, int fieldSize)
      Write the text representation of an 32-bit integer (an "int") to the file with a specified field size.
      void print​(long number)
      Write the text representation of an 64-bit integer (a "long") to the file.
      void print​(long number, int fieldSize)
      Write the text representation of an 64-bit integer (a "long") to the file with a specified field size.
      void print​(short number)
      Write the text representation of an 16-bit integer (a "short") to the file.
      void print​(short number, int fieldSize)
      Write the text representation of an 16-bit integer (a "short") to the file with a specified field size.
      void print​(String text)
      Write a string to the file.
      void print​(String text, int fieldSize)
      Write a string to the file with a specified field size..
      void println()
      Write a newline to the file.
      void println​(boolean value)
      Write the text representation of a boolean to the file followed by a newline.
      void println​(boolean value, int fieldSize)
      Write the text representation of a boolean to the file with a specified field size followed by a newline.
      void println​(byte number)
      Write the text representation of an 8-bit integer (a "byte") to the file followed by a newline.
      void println​(byte number, int fieldSize)
      Write the text representation of an 8-bit integer (a "byte") to the file with a specified field size followed by a newline.
      void println​(char ch)
      Write a character to the file followed by a newline.
      void println​(char ch, int fieldSize)
      Write a character to the file with a specified field size..
      void println​(double number)
      Write a double precision floating point number (a "double") to the file followed by a newline.
      void println​(double number, int fieldSize)
      Write a double precision floating point number (a "double") to the file with a specified field size followed by a newline.
      void println​(double number, int fieldSize, int decimalPlaces)
      Write a double precision floating point number (a "double") to the file with a specified field size and a specified number of decimal places followed by a newline.
      void println​(float number)
      Write a floating point number (a "float") to the file followed by a newline.
      void println​(float number, int fieldSize)
      Write a floating point number (a "float") to the file with a specified field size followed by a newline.
      void println​(float number, int fieldSize, int decimalPlaces)
      Write a floating point number (a "double") to the file with a specified field size and a specified number of decimal places followed by a newline.
      void println​(int number)
      Write the text representation of an 32-bit integer (an "int") to the file followed by a newline.
      void println​(int number, int fieldSize)
      Write the text representation of an 32-bit integer (an "int") to the file with a specified field size followed by a newline.
      void println​(long number)
      Write the text representation of an 64-bit integer (a "long") to the file followed by a newline.
      void println​(long number, int fieldSize)
      Write the text representation of an 64-bit integer (a "long") to the file with a specified field size followed by a newline.
      void println​(short number)
      Write the text representation of an 16-bit integer (a "short") to the file followed by a newline.
      void println​(short number, int fieldSize)
      Write the text representation of an 16-bit integer (a "short") to the file with a specified field size followed by a newline.
      void println​(String text)
      Write a string to the file followed by a newline.
      void println​(String text, int fieldSize)
      Write a string to the file with a specified field size followed by a newline.
    • Field Detail

      • fileName

        protected String fileName
        The file name.
      • closed

        protected boolean closed
        Set if the file has been closed.
      • useStandardIO

        protected boolean useStandardIO
        Indicator whether to write to standard output or a file.
      • lineSeparator

        protected String lineSeparator
        The line separator in files
    • Constructor Detail

      • TextOutputFile

        public TextOutputFile()
        Contructor - TextOutputFile to write to standard output.
      • TextOutputFile

        public TextOutputFile​(File file)
        Contructor - TextOutputFile to write to a File.
        Parameters:
        file - - File to be opened.
      • TextOutputFile

        public TextOutputFile​(File file,
                              boolean append)
        Contructor - TextOutputFile to write or append to a File.
        Parameters:
        file - - File to be opened.
        append - - True if file is to be appended to.
      • TextOutputFile

        public TextOutputFile​(String fileName)
        Contructor - TextFile to write to file with specified name.
        Parameters:
        fileName - - Name of the file to be opened.
      • TextOutputFile

        public TextOutputFile​(String fileName,
                              boolean append)
        Contructor - TextFile to write or append to file with specified name.
        Parameters:
        fileName - - Name of the file to be opened.
        append - - True if file is to be appended to.
    • Method Detail

      • close

        public void close()
        Close the file to further writing.
      • isStandardOut

        public boolean isStandardOut()
      • print

        public void print​(byte number)
        Write the text representation of an 8-bit integer (a "byte") to the file.
        Parameters:
        number - The number to be written to the file.
      • print

        public void print​(byte number,
                          int fieldSize)
        Write the text representation of an 8-bit integer (a "byte") to the file with a specified field size.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • print

        public void print​(char ch)
        Write a character to the file.
        Parameters:
        ch - The character to be written to the file.
      • print

        public void print​(char ch,
                          int fieldSize)
        Write a character to the file with a specified field size..
        Parameters:
        ch - The character to be written to the file.
        fieldSize - The field width that the character is to be written in.
      • print

        public void print​(double number)
        Write a double precision floating point number (a "double") to the file.
        Parameters:
        number - The number to be written to the file.
      • print

        public void print​(double number,
                          int fieldSize)
        Write a double precision floating point number (a "double") to the file with a specified field size.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • print

        public void print​(double number,
                          int fieldSize,
                          int decimalPlaces)
        Write a double precision floating point number (a "double") to the file with a specified field size and a specified number of decimal places.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
        decimalPlaces - The number of decimal places of the number to be displayed.
      • print

        public void print​(float number)
        Write a floating point number (a "float") to the file.
        Parameters:
        number - The number to be written to the file.
      • print

        public void print​(float number,
                          int fieldSize)
        Write a floating point number (a "float") to the file with a specified field size.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • print

        public void print​(float number,
                          int fieldSize,
                          int decimalPlaces)
        Write a floating point number (a "double") to the file with a specified field size and a specified number of decimal places.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
        decimalPlaces - The number of decimal places of the number to be displayed.
      • print

        public void print​(int number)
        Write the text representation of an 32-bit integer (an "int") to the file.
        Parameters:
        number - The number to be written to the file.
      • print

        public void print​(int number,
                          int fieldSize)
        Write the text representation of an 32-bit integer (an "int") to the file with a specified field size.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • print

        public void print​(long number)
        Write the text representation of an 64-bit integer (a "long") to the file.
        Parameters:
        number - The number to be written to the file.
      • print

        public void print​(long number,
                          int fieldSize)
        Write the text representation of an 64-bit integer (a "long") to the file with a specified field size.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • print

        public void print​(String text)
        Write a string to the file.
        Parameters:
        text - The string to be written to the file.
      • print

        public void print​(String text,
                          int fieldSize)
        Write a string to the file with a specified field size..
        Parameters:
        text - The string to be written to the file.
        fieldSize - The field width that the string is to be written in.
      • print

        public void print​(short number)
        Write the text representation of an 16-bit integer (a "short") to the file.
        Parameters:
        number - The number to be written to the file.
      • print

        public void print​(short number,
                          int fieldSize)
        Write the text representation of an 16-bit integer (a "short") to the file with a specified field size.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • print

        public void print​(boolean value)
        Write the text representation of a boolean to the file.
        Parameters:
        value - The boolean to be written to the file.
      • print

        public void print​(boolean value,
                          int fieldSize)
        Write the text representation of a boolean to the file with a specified field size.
        Parameters:
        value - The boolean to be written to the file.
        fieldSize - The field width that the boolean is to be written in.
      • println

        public void println()
        Write a newline to the file.
      • println

        public void println​(byte number)
        Write the text representation of an 8-bit integer (a "byte") to the file followed by a newline.
        Parameters:
        number - The number to be written to the file.
      • println

        public void println​(byte number,
                            int fieldSize)
        Write the text representation of an 8-bit integer (a "byte") to the file with a specified field size followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • println

        public void println​(char ch)
        Write a character to the file followed by a newline.
        Parameters:
        ch - The character to be written to the file.
      • println

        public void println​(char ch,
                            int fieldSize)
        Write a character to the file with a specified field size..
        Parameters:
        ch - The character to be written to the file.
        fieldSize - The field width that the character is to be written in.
      • println

        public void println​(double number)
        Write a double precision floating point number (a "double") to the file followed by a newline.
        Parameters:
        number - The number to be written to the file.
      • println

        public void println​(double number,
                            int fieldSize)
        Write a double precision floating point number (a "double") to the file with a specified field size followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • println

        public void println​(double number,
                            int fieldSize,
                            int decimalPlaces)
        Write a double precision floating point number (a "double") to the file with a specified field size and a specified number of decimal places followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
        decimalPlaces - The number of decimal places of the number to be displayed.
      • println

        public void println​(float number)
        Write a floating point number (a "float") to the file followed by a newline.
        Parameters:
        number - The number to be written to the file.
      • println

        public void println​(float number,
                            int fieldSize)
        Write a floating point number (a "float") to the file with a specified field size followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • println

        public void println​(float number,
                            int fieldSize,
                            int decimalPlaces)
        Write a floating point number (a "double") to the file with a specified field size and a specified number of decimal places followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
        decimalPlaces - The number of decimal places of the number to be displayed.
      • println

        public void println​(int number)
        Write the text representation of an 32-bit integer (an "int") to the file followed by a newline.
        Parameters:
        number - The number to be written to the file.
      • println

        public void println​(int number,
                            int fieldSize)
        Write the text representation of an 32-bit integer (an "int") to the file with a specified field size followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • println

        public void println​(long number)
        Write the text representation of an 64-bit integer (a "long") to the file followed by a newline.
        Parameters:
        number - The number to be written to the file.
      • println

        public void println​(long number,
                            int fieldSize)
        Write the text representation of an 64-bit integer (a "long") to the file with a specified field size followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • println

        public void println​(String text)
        Write a string to the file followed by a newline.
        Parameters:
        text - The string to be written to the file.
      • println

        public void println​(String text,
                            int fieldSize)
        Write a string to the file with a specified field size followed by a newline.
        Parameters:
        text - The string to be written to the file.
        fieldSize - The field width that the string is to be written in.
      • println

        public void println​(short number)
        Write the text representation of an 16-bit integer (a "short") to the file followed by a newline.
        Parameters:
        number - The number to be written to the file.
      • println

        public void println​(short number,
                            int fieldSize)
        Write the text representation of an 16-bit integer (a "short") to the file with a specified field size followed by a newline.
        Parameters:
        number - The number to be written to the file.
        fieldSize - The field width that the number is to be written in.
      • println

        public void println​(boolean value)
        Write the text representation of a boolean to the file followed by a newline.
        Parameters:
        value - The boolean to be written to the file.
      • println

        public void println​(boolean value,
                            int fieldSize)
        Write the text representation of a boolean to the file with a specified field size followed by a newline.
        Parameters:
        value - The boolean to be written to the file.
        fieldSize - The field width that the boolean is to be written in.