Package util
Class ReadFile
java.lang.Object
util.ReadFile
- Direct Known Subclasses:
ReadWord
ReadFile is used to read in a file from a given directory.
- Since:
- 2023-02
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if the list of contents is empty.boolean
Checks if a file exists.Gets the directory.Returns the file contents.Gets a random element from the list.void
readFile()
Reads the file using the directory.Adds each line that isn't null to the contents.void
setDirectory
(String directory) Sets the directory.
-
Constructor Details
-
ReadFile
Initializes the ReadFile object and assigns directory.- Parameters:
directory
- directory
-
-
Method Details
-
checkFileExists
public boolean checkFileExists()Checks if a file exists.- Returns:
- boolean
-
checkContentsEmpty
public boolean checkContentsEmpty()Checks if the list of contents is empty.- Returns:
- boolean
-
readFile
public void readFile()Reads the file using the directory.Adds each line that isn't null to the contents. -
getFileContents
Returns the file contents.- Returns:
- List
-
getRandomElement
Gets a random element from the list.- Returns:
- String
-
getDirectory
Gets the directory.- Returns:
- String
-
setDirectory
Sets the directory.- Parameters:
directory
-
-