Package org.cis1200
Class FileUtilities
java.lang.Object
org.cis1200.FileUtilities
This class organizes some static methods for working with File IO.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedReader
fileToReader
(String filePath) Takes in a filename and creates a BufferedReader.static void
writeStringsToFile
(List<String> stringsToWrite, String filePath, boolean append) Given aList
ofString
s, writes them to a file (oneString
per line in the file).
-
Constructor Details
-
FileUtilities
public FileUtilities()
-
-
Method Details
-
fileToReader
Takes in a filename and creates a BufferedReader. See Java's documentation for BufferedReader to learn how to construct one given a path to a file.- Parameters:
filePath
- the path to the CSV file to be turned to a BufferedReader- Returns:
- a BufferedReader of the provided file contents
- Throws:
IllegalArgumentException
- if filePath is null or if the file doesn't exist
-
writeStringsToFile
Given aList
ofString
s, writes them to a file (oneString
per line in the file). This method usesBufferedWriter
, the flip side toBufferedReader
. It may be useful to look at the JavaDocs forFileWriter
.You may assume none of the arguments or strings passed in will be null.
If the process of opening the file or writing the data triggers an
IOException
, you should catch it and stop writing. (You can also print an error message to the terminal, but we will not test that behavior.)- Parameters:
stringsToWrite
- A List of Strings to write to the filefilePath
- the string containing the path to the file where the tweets should be writtenappend
- a boolean indicating whether the new tweets should be appended to the current file or should overwrite its previous contents
-