Package HAL.Tools
Class FileIO
- java.lang.Object
-
- HAL.Tools.FileIO
-
public class FileIO extends java.lang.Objectused 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.StringfileNamecharmodejava.io.BufferedReaderreaderjava.io.DataInputStreamreaderBincharReadWriteAppendjava.io.FileInputStreamserialfileReaderjava.io.FileOutputStreamserialfileWriterjava.io.ObjectInputStreamserialobjectReaderjava.io.ObjectOutputStreamserialobjectWriterjava.io.BufferedWriterwriterjava.io.DataOutputStreamwriterBin
-
Constructor Summary
Constructors Constructor Description FileIO(java.lang.String fileName, java.lang.String mode)
-
Method Summary
Modifier and Type Method Description voidClose()used to Close the file.booleanIsClosed()returns whether the FileIO object has closed the file alreadydoublelength()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 stringsbooleanReadBinBool()requires readBinary mode ("rb") reads a boolean from the binary filevoidReadBinBools(boolean[] putHere)doubleReadBinDouble()requires readBinary mode ("rb") reads a single double from the binary filevoidReadBinDoubles(double[] putHere)floatReadBinFloat()requires readBinary mode ("rb") reads a single float from the binary filevoidReadBinFloats(float[] putHere)intReadBinInt()requires readBinary mode ("rb") reads a single int from the binary filevoidReadBinInts(int[] putHere)longReadBinLong()requires readBinary mode ("rb") reads a single long from the binary filevoidReadBinLongs(long[] putHere)java.lang.StringReadBinString()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.StringReadLine()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.ObjectReadObject()voidWrite(java.lang.String text)requires write mode or append mode ("w"/"a")voidWriteBinBool(boolean writeMe)requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single boolean to the binary filevoidWriteBinBools(boolean[] writeMe)voidWriteBinDouble(double writeMe)requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single double to the binary filevoidWriteBinDoubles(double[] writeMe)voidWriteBinFloat(float writeMe)requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single float to the binary filevoidWriteBinFloats(float[] writeMe)voidWriteBinInt(int writeMe)requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single int to the binary filevoidWriteBinInts(int[] writeMe)voidWriteBinLong(long writeMe)requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a single long to the binary filevoidWriteBinLongs(long[] writeMe)voidWriteBinString(java.lang.String writeMe)requires writeBinary mode or appendBinary mode ("wb"/"ab") writes a string to the binary filevoidWriteDelimit(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 delimitervoidWriteDelimit(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 delimitervoidWriteDelimit(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 delimitervoidWriteDelimit(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 delimitervoidWriteDelimit(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() methodvoidWriteDelimit(java.lang.String[] data, java.lang.String delimiter)voidWriteDelimit(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() methodvoidWriteObject(java.lang.Object toSave)voidWriteStrings(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
-
-