Package PamUtils
Class TxtFileUtils
java.lang.Object
PamUtils.TxtFileUtils
Some functions to load and import data stored in text files (includes .csv files)
- Author:
- Jamie Macaulay
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
exportMatlab2DArray
(double[][] array, int dp) static boolean
exportTxtData
(String filename, ArrayList<String> dataToWrite) Write string data to a fileimportCSVData
(String filename) Load data from a .csv file into a 2D ArrayList.importTxtData
(String filename, String delimeter) Load data from a text file into a 2D ArrayList. importTxtData
(String filename, String delimeter, boolean nanOk) Load data from a text file into a 2D ArrayList. importTxtDataToString
(String filePath) Load data from a text file into a 2D ArrayList. importTxtDataToString
(String filePath, boolean nanOk) Load data from a text file into a 2D ArrayList. importTxtDataToString
(String filePath, String delimeter) Load data from a text file into a 2D ArrayList. importTxtDataToString
(String filename, String delimeter, boolean nanOk) Load data from a text file into a 2D ArrayList. importTxtToCollection
(String filename) Import text data into an array of strings.parseTxtLine
(String line, String delimiter) Convert into ArrayList of strings based on a delimiter.parseTxtLine
(String line, String delimiter, boolean nanOk) Convert into ArrayList of strings based on a delimiterstatic void
Print out data.
-
Constructor Details
-
TxtFileUtils
public TxtFileUtils()
-
-
Method Details
-
importCSVData
Load data from a .csv file into a 2D ArrayList.- Parameters:
filename
-- Returns:
- a 2D array of values.
-
importTxtData
Load data from a text file into a 2D ArrayList. Elements will be separated based on the delimiter string input. Note that lines containing NaN values are skipped. - Parameters:
filename
- - file path to import.delimeter
- - separate elements in the file using the delimiter. e.g. \\t for tab, \\s+ for space, , for .csv.- Returns:
- 2D ArrayList
of rows and columns defined by delimiter.
-
importTxtData
public static ArrayList<ArrayList<Double>> importTxtData(String filename, String delimeter, boolean nanOk) Load data from a text file into a 2D ArrayList. Elements will be separated based on the delimiter string input. Lines containing NaN values are included if nanOk = true, or skipped if nanOk=false. NaN will be replaced with nulls. - Parameters:
filename
- - file path to import.delimeter
- - separate elements in the file using the delimiter. e.g. \\t for tab, \\s+ for space, , for .csv.nanOk
- leave rows containing NaN values if true, skip rows if false- Returns:
- 2D ArrayList
of rows and columns defined by delimiter.
-
importTxtToCollection
Import text data into an array of strings.- Parameters:
filename
- - file path of file to import.
-
importTxtDataToString
Load data from a text file into a 2D ArrayList. Elements will be separated based on the delimiter string input. Any line containing NaN will be ignored - Parameters:
filePath
- - file path to import.- Returns:
- 2D ArrayList
of rows and columns defined by delimiter.
-
importTxtDataToString
Load data from a text file into a 2D ArrayList. Elements will be separated based on the delimiter string input. - Parameters:
filePath
- - file path to import.nanOk
- leave rows containing NaN values if true, skip rows if false- Returns:
- 2D ArrayList
of rows and columns defined by delimiter.
-
importTxtDataToString
Load data from a text file into a 2D ArrayList. Elements will be separated based on the delimiter string input. Any line containing NaN will be ignored - Parameters:
filePath
- - file path to import.delimeter
- - separate elements in the file using the delimiter.- Returns:
- 2D ArrayList
of rows and columns defined by delimiter.
-
importTxtDataToString
public static ArrayList<ArrayList<String>> importTxtDataToString(String filename, String delimeter, boolean nanOk) Load data from a text file into a 2D ArrayList. Elements will be separated based on the delimiter string input. - Parameters:
filename
- - file path to import.delimeter
- - separate elements in the file using the delimiter.nanOk
- leave rows containing NaN values if true, skip rows if false- Returns:
- 2D ArrayList
of rows and columns defined by delimiter.
-
parseTxtLine
Convert into ArrayList of strings based on a delimiter. Any lines containing NaN are ignored- Parameters:
line
- - the line to parsedelimiter
- the delimiter to use- Returns:
- split strings based on delimiter.
-
parseTxtLine
Convert into ArrayList of strings based on a delimiter- Parameters:
line
- - the line to parsedelimiter
- the delimiter to usenanOk
- leave rows containing NaN values if true, skip rows if false- Returns:
- split strings based on delimiter.
-
printData
Print out data.- Parameters:
data
-
-
exportTxtData
Write string data to a file- Parameters:
filename
- the filename to write todataToWrite
- An ArrayList of String objects to write. Each index in the array will be written on a new line- Returns:
- true if successful, false if an exception was thrown
-
exportMatlab2DArray
-