Package org.cis1200

Class FileUtilities

java.lang.Object
org.cis1200.FileUtilities

public class FileUtilities extends Object
This class organizes some static methods for working with File IO.
  • Constructor Details

    • FileUtilities

      public FileUtilities()
  • Method Details

    • fileToReader

      public static BufferedReader fileToReader(String filePath)
      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

      public static void writeStringsToFile(List<String> stringsToWrite, String filePath, boolean append)
      Given a List of Strings, writes them to a file (one String per line in the file). This method uses BufferedWriter, the flip side to BufferedReader. It may be useful to look at the JavaDocs for FileWriter.

      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 file
      filePath - the string containing the path to the file where the tweets should be written
      append - a boolean indicating whether the new tweets should be appended to the current file or should overwrite its previous contents