summaryrefslogtreecommitdiff
path: root/src/Reader.java
diff options
context:
space:
mode:
authorArghKevin <kagheli@student.sdccd.edu>2024-04-29 13:32:18 -0700
committerArghKevin <kagheli@student.sdccd.edu>2024-04-29 13:32:18 -0700
commitb91b582d8a6c0b2e78a20a517c6e0d3b036725d8 (patch)
tree615a0ed4830a3ef1b17ec505001771962a5933f1 /src/Reader.java
parent55669ea76c7a08dfbaca5898070404c0f60d476d (diff)
Week 2. Stubs. Start of GUI.
Diffstat (limited to 'src/Reader.java')
-rw-r--r--src/Reader.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Reader.java b/src/Reader.java
new file mode 100644
index 0000000..934bf5f
--- /dev/null
+++ b/src/Reader.java
@@ -0,0 +1,49 @@
+import java.io.*;
+import java.util.Scanner;
+
+/*
+ * @author
+ * Kian Agheli
+ *
+ * References:
+ *
+ * Date:
+ * 2024-04-28
+ *
+ * Purpose of class:
+ * Read from a file.
+ */
+
+class Reader {
+ private File file; // A Reader has-a file.
+ private String contents; // A Reader has-a set of contents.
+
+ public Reader(File file) {
+ this.file = file;
+ contents = null;
+ Scanner scan = null;
+ try {
+ /* Scan over the contents of the input file. */
+ scan = new Scanner(file);
+ /* Save to object. */
+ while (scan.hasNextLine()) {
+ contents += scan.nextLine();
+ }
+ /* On exception, exit. */
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ System.exit(1);
+ } finally {
+ if (scan != null) {
+ scan.close();
+ }
+ }
+ }
+
+ /*
+ * @return the contents of the file.
+ */
+ String getContents() {
+ return contents;
+ }
+}