Package HAL.Tools
Class FileIO
- java.lang.Object
-
- HAL.Tools.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
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
fileName
char
mode
java.io.BufferedReader
reader
java.io.DataInputStream
readerBin
char
ReadWriteAppend
java.io.FileInputStream
serialfileReader
java.io.FileOutputStream
serialfileWriter
java.io.ObjectInputStream
serialobjectReader
java.io.ObjectOutputStream
serialobjectWriter
java.io.BufferedWriter
writer
java.io.DataOutputStream
writerBin
-
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 alreadydouble
length()
returns the length of the file, or 0 if the file does not existjava.util.ArrayList<java.lang.String>
Read()
requires read mode ("r") returns an array list of all lines from the file as stringsboolean
ReadBinBool()
requires readBinary mode ("rb") reads a boolean from the binary filevoid
ReadBinBools(boolean[] putHere)
double
ReadBinDouble()
requires readBinary mode ("rb") reads a single double from the binary filevoid
ReadBinDoubles(double[] putHere)
float
ReadBinFloat()
requires readBinary mode ("rb") reads a single float from the binary filevoid
ReadBinFloats(float[] putHere)
int
ReadBinInt()
requires readBinary mode ("rb") reads a single int from the binary filevoid
ReadBinInts(int[] putHere)
long
ReadBinLong()
requires readBinary mode ("rb") reads a single long from the binary filevoid
ReadBinLongs(long[] putHere)
java.lang.String
ReadBinString()
requires readBinary mode ("rb") reads a string from the binary filejava.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 linejava.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 linejava.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 linejava.lang.String
ReadLine()
requires read mode ("r") returns one line from the file as a stringjava.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 segmentsdouble[]
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 linefloat[]
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 lineint[]
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 linelong[]
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 linejava.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 linejava.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 filevoid
WriteBinBools(boolean[] writeMe)
void
WriteBinDouble(double writeMe)
requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single double to the binary filevoid
WriteBinDoubles(double[] writeMe)
void
WriteBinFloat(float writeMe)
requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single float to the binary filevoid
WriteBinFloats(float[] writeMe)
void
WriteBinInt(int writeMe)
requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single int to the binary filevoid
WriteBinInts(int[] writeMe)
void
WriteBinLong(long writeMe)
requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single long to the binary filevoid
WriteBinLongs(long[] writeMe)
void
WriteBinString(java.lang.String writeMe)
requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a string to the binary filevoid
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 delimitervoid
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 delimitervoid
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 delimitervoid
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 delimitervoid
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() methodvoid
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() methodvoid
WriteObject(java.lang.Object toSave)
void
WriteStrings(java.util.List<java.lang.String> data, java.lang.String delimiter)
-
-
-
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
-
-
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 writtendelimiter
- 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 writtendelimiter
- 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
-
-