Package HAL.Tools

Class FileIO


  • public class FileIO
    extends java.lang.Object
    used to read from and write to files, can open a file in "read" "write", "readBinary" and "writeBinary" modes. FileIO objects keep their mode and file permanently. to open a different file or change modes, create a different new FileIO object
    • Constructor Summary

      Constructors 
      Constructor Description
      FileIO​(java.lang.String fileName, java.lang.String mode)  
    • Method Summary

      Modifier and Type Method Description
      void Close()
      used to Close the file.
      boolean IsClosed()
      returns whether the FileIO object has closed the file already
      double length()
      returns the length of the file, or 0 if the file does not exist
      java.util.ArrayList<java.lang.String> Read()
      requires read mode ("r") returns an array list of all lines from the file as strings
      boolean ReadBinBool()
      requires readBinary mode ("rb") reads a boolean from the binary file
      void ReadBinBools​(boolean[] putHere)  
      double ReadBinDouble()
      requires readBinary mode ("rb") reads a single double from the binary file
      void ReadBinDoubles​(double[] putHere)  
      float ReadBinFloat()
      requires readBinary mode ("rb") reads a single float from the binary file
      void ReadBinFloats​(float[] putHere)  
      int ReadBinInt()
      requires readBinary mode ("rb") reads a single int from the binary file
      void ReadBinInts​(int[] putHere)  
      long ReadBinLong()
      requires readBinary mode ("rb") reads a single long from the binary file
      void ReadBinLongs​(long[] putHere)  
      java.lang.String ReadBinString()
      requires readBinary mode ("rb") reads a string from the binary file
      java.util.ArrayList<java.lang.String[]> ReadDelimit​(java.lang.String delimiter)
      requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of line segments from that line
      java.util.ArrayList<double[]> ReadDoubles​(java.lang.String delimiter)
      requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of doubles from that line
      java.util.ArrayList<int[]> ReadInts​(java.lang.String delimiter)
      requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of ints from that line
      java.lang.String ReadLine()
      requires read mode ("r") returns one line from the file as a string
      java.lang.String[] ReadLineDelimit​(java.lang.String delimiter)
      requires read mode ("r") pulls a line from the file, splits it by the delimiter, and returns an array of line segments
      double[] ReadLineDoubles​(java.lang.String delimiter)
      requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of doubles from that line
      float[] ReadLineFloats​(java.lang.String delimiter)
      requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of floats from that line
      int[] ReadLineInts​(java.lang.String delimiter)
      requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of integers from that line
      long[] ReadLineLongs​(java.lang.String delimiter)
      requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of longs from that line
      java.util.ArrayList<long[]> ReadLongs​(java.lang.String delimiter)
      requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of longs from that line
      java.lang.Object ReadObject()  
      void Write​(java.lang.String text)
      requires write mode or append mode ("w"/"a")
      void WriteBinBool​(boolean writeMe)
      requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single boolean to the binary file
      void WriteBinBools​(boolean[] writeMe)  
      void WriteBinDouble​(double writeMe)
      requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single double to the binary file
      void WriteBinDoubles​(double[] writeMe)  
      void WriteBinFloat​(float writeMe)
      requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single float to the binary file
      void WriteBinFloats​(float[] writeMe)  
      void WriteBinInt​(int writeMe)
      requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single int to the binary file
      void WriteBinInts​(int[] writeMe)  
      void WriteBinLong​(long writeMe)
      requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single long to the binary file
      void WriteBinLongs​(long[] writeMe)  
      void WriteBinString​(java.lang.String writeMe)
      requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a string to the binary file
      void WriteDelimit​(double[] data, java.lang.String delimiter)
      requires write mode or append mode ("w"/"a") writes the array of doubles to the file, separated by the delimiter
      void WriteDelimit​(float[] data, java.lang.String delimiter)
      requires write mode or append mode ("w"/"a") writes the array of floats to the file, separated by the delimiter
      void WriteDelimit​(int[] data, java.lang.String delimiter)
      requires write mode or append mode ("w"/"a") writes the array of ints to the file, separated by the delimiter
      void WriteDelimit​(long[] data, java.lang.String delimiter)
      requires write mode or append mode ("w"/"a") writes the array of longs to the file, separated by the delimiter
      void WriteDelimit​(java.lang.Object[] data, java.lang.String delimiter)
      requires write mode or append mode ("w"/"a") the objects in the array are written to the output file using the toString() method
      void WriteDelimit​(java.lang.String[] data, java.lang.String delimiter)  
      void WriteDelimit​(java.util.List<java.lang.Object> data, java.lang.String delimiter)
      requires write mode or append mode ("w"/"a") the objects in the list are written to the output file using the toString() method
      void WriteObject​(java.lang.Object toSave)  
      void WriteStrings​(java.util.List<java.lang.String> data, java.lang.String delimiter)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • fileName

        public final java.lang.String fileName
      • ReadWriteAppend

        public final char ReadWriteAppend
      • mode

        public final char mode
      • reader

        public final java.io.BufferedReader reader
      • writer

        public final java.io.BufferedWriter writer
      • writerBin

        public final java.io.DataOutputStream writerBin
      • readerBin

        public final java.io.DataInputStream readerBin
      • serialfileReader

        public final java.io.FileInputStream serialfileReader
      • serialobjectReader

        public final java.io.ObjectInputStream serialobjectReader
      • serialfileWriter

        public final java.io.FileOutputStream serialfileWriter
      • serialobjectWriter

        public final java.io.ObjectOutputStream serialobjectWriter
    • Constructor Detail

      • FileIO

        public FileIO​(java.lang.String fileName,
                      java.lang.String mode)
        Parameters:
        fileName - name of the file to read from or write to
        mode - should be either "r":read, "w":write, "rb":readBinary, "wb":writeBinary, "rs": readSerialization, "ws": writeSerialization
    • Method Detail

      • IsClosed

        public boolean IsClosed()
        returns whether the FileIO object has closed the file already
        Returns:
      • ReadLineDelimit

        public java.lang.String[] ReadLineDelimit​(java.lang.String delimiter)
        requires read mode ("r") pulls a line from the file, splits it by the delimiter, and returns an array of line segments
        Parameters:
        delimiter - the delimiter used to divide the line
      • ReadLineInts

        public int[] ReadLineInts​(java.lang.String delimiter)
        requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of integers from that line
        Parameters:
        delimiter - the delimiter used to divide the line
      • ReadLineFloats

        public float[] ReadLineFloats​(java.lang.String delimiter)
        requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of floats from that line
        Parameters:
        delimiter - the delimiter used to divide the line
      • ReadLineDoubles

        public double[] ReadLineDoubles​(java.lang.String delimiter)
        requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of doubles from that line
        Parameters:
        delimiter - the delimiter used to divide the line
      • ReadLineLongs

        public long[] ReadLineLongs​(java.lang.String delimiter)
        requires read mode ("r") pulls a line from the file, splits it by the delimeter and returns an array of longs from that line
        Parameters:
        delimiter - the delimiter used to divide the line
      • ReadDelimit

        public java.util.ArrayList<java.lang.String[]> ReadDelimit​(java.lang.String delimiter)
        requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of line segments from that line
        Parameters:
        delimiter - the delimiter used to divide the lines
      • ReadDoubles

        public java.util.ArrayList<double[]> ReadDoubles​(java.lang.String delimiter)
        requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of doubles from that line
        Parameters:
        delimiter - the delimiter used to divide the lines
      • ReadInts

        public java.util.ArrayList<int[]> ReadInts​(java.lang.String delimiter)
        requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of ints from that line
        Parameters:
        delimiter - the delimiter used to divide the lines
      • ReadLongs

        public java.util.ArrayList<long[]> ReadLongs​(java.lang.String delimiter)
        requires read mode ("r") pulls all lines from the file, splits them by the delimiter, and returns an arraylist, where each entry is an array of longs from that line
        Parameters:
        delimiter - the delimiter used to divide the lines
      • ReadLine

        public java.lang.String ReadLine()
        requires read mode ("r") returns one line from the file as a string
      • Read

        public java.util.ArrayList<java.lang.String> Read()
        requires read mode ("r") returns an array list of all lines from the file as strings
      • Write

        public void Write​(java.lang.String text)
        requires write mode or append mode ("w"/"a")
        Parameters:
        text - writes the line to the file
      • WriteDelimit

        public void WriteDelimit​(java.util.List<java.lang.Object> data,
                                 java.lang.String delimiter)
        requires write mode or append mode ("w"/"a") the objects in the list are written to the output file using the toString() method
        Parameters:
        data - a list of objects to be written
        delimiter - the delimiter used to separate each object
      • WriteStrings

        public void WriteStrings​(java.util.List<java.lang.String> data,
                                 java.lang.String delimiter)
      • WriteDelimit

        public void WriteDelimit​(java.lang.Object[] data,
                                 java.lang.String delimiter)
        requires write mode or append mode ("w"/"a") the objects in the array are written to the output file using the toString() method
        Parameters:
        data - an array of objects to be written
        delimiter - the delimiter used to separate each object
      • WriteDelimit

        public void WriteDelimit​(int[] data,
                                 java.lang.String delimiter)
        requires write mode or append mode ("w"/"a") writes the array of ints to the file, separated by the delimiter
      • WriteDelimit

        public void WriteDelimit​(long[] data,
                                 java.lang.String delimiter)
        requires write mode or append mode ("w"/"a") writes the array of longs to the file, separated by the delimiter
      • WriteDelimit

        public void WriteDelimit​(float[] data,
                                 java.lang.String delimiter)
        requires write mode or append mode ("w"/"a") writes the array of floats to the file, separated by the delimiter
      • WriteDelimit

        public void WriteDelimit​(double[] data,
                                 java.lang.String delimiter)
        requires write mode or append mode ("w"/"a") writes the array of doubles to the file, separated by the delimiter
      • WriteDelimit

        public void WriteDelimit​(java.lang.String[] data,
                                 java.lang.String delimiter)
      • WriteBinDoubles

        public void WriteBinDoubles​(double[] writeMe)
      • WriteBinFloats

        public void WriteBinFloats​(float[] writeMe)
      • WriteBinInts

        public void WriteBinInts​(int[] writeMe)
      • WriteBinLongs

        public void WriteBinLongs​(long[] writeMe)
      • WriteBinBools

        public void WriteBinBools​(boolean[] writeMe)
      • WriteBinDouble

        public void WriteBinDouble​(double writeMe)
        requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single double to the binary file
      • WriteBinFloat

        public void WriteBinFloat​(float writeMe)
        requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single float to the binary file
      • WriteBinInt

        public void WriteBinInt​(int writeMe)
        requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single int to the binary file
      • WriteBinLong

        public void WriteBinLong​(long writeMe)
        requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single long to the binary file
      • WriteBinString

        public void WriteBinString​(java.lang.String writeMe)
        requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a string to the binary file
      • WriteBinBool

        public void WriteBinBool​(boolean writeMe)
        requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single boolean to the binary file
      • ReadBinDouble

        public double ReadBinDouble()
        requires readBinary mode ("rb") reads a single double from the binary file
      • ReadBinFloat

        public float ReadBinFloat()
        requires readBinary mode ("rb") reads a single float from the binary file
      • ReadBinInt

        public int ReadBinInt()
        requires readBinary mode ("rb") reads a single int from the binary file
      • ReadBinLong

        public long ReadBinLong()
        requires readBinary mode ("rb") reads a single long from the binary file
      • ReadBinString

        public java.lang.String ReadBinString()
        requires readBinary mode ("rb") reads a string from the binary file
      • ReadBinBool

        public boolean ReadBinBool()
        requires readBinary mode ("rb") reads a boolean from the binary file
      • ReadBinDoubles

        public void ReadBinDoubles​(double[] putHere)
      • ReadBinFloats

        public void ReadBinFloats​(float[] putHere)
      • ReadBinInts

        public void ReadBinInts​(int[] putHere)
      • ReadBinLongs

        public void ReadBinLongs​(long[] putHere)
      • ReadBinBools

        public void ReadBinBools​(boolean[] putHere)
      • ReadObject

        public java.lang.Object ReadObject()
      • WriteObject

        public void WriteObject​(java.lang.Object toSave)
      • length

        public double length()
        returns the length of the file, or 0 if the file does not exist
      • Close

        public void Close()
        used to Close the file. if forgotten, write calls may never finish