From 2ce3753fe8c88ca3780d0774eaacdff7cd28d5a4 Mon Sep 17 00:00:00 2001
From: inseo <i32kim@uwaterloo.ca>
Date: Sat, 11 Feb 2023 19:02:42 -0500
Subject: [PATCH] File management has been finished

---
 .../kotlin/notes/multi/console/Console.kt     |  9 +++--
 console/test/hello.txt                        |  1 +
 .../notes/multi/utilities/Filemanager.kt      | 40 +++++++++++++------
 3 files changed, 33 insertions(+), 17 deletions(-)
 create mode 100644 console/test/hello.txt

diff --git a/console/src/main/kotlin/notes/multi/console/Console.kt b/console/src/main/kotlin/notes/multi/console/Console.kt
index 6999949..178b410 100644
--- a/console/src/main/kotlin/notes/multi/console/Console.kt
+++ b/console/src/main/kotlin/notes/multi/console/Console.kt
@@ -3,10 +3,11 @@
  */
 package notes.multi.console
 
-import notes.multi.utilities.StringUtils
-
-import org.apache.commons.text.WordUtils
+import notes.multi.utilities.Filemanager
 
 fun main() {
-    println("this is multi setup")
+    // thesea re test functions feel free to use
+    val f = Filemanager("${System.getProperty("user.dir")}/test/", "hello.txt")
+    f.writefile("hello world")
+    println(f.openfile())
 }
diff --git a/console/test/hello.txt b/console/test/hello.txt
new file mode 100644
index 0000000..95d09f2
--- /dev/null
+++ b/console/test/hello.txt
@@ -0,0 +1 @@
+hello world
\ No newline at end of file
diff --git a/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt b/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt
index 8963081..b7e723f 100644
--- a/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt
+++ b/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt
@@ -1,29 +1,43 @@
 package notes.multi.utilities
 
 import java.io.File
-import java.io.FileInputStream
-import java.util.*
-import kotlin.io.path.exists
-class Filemanager(val dir: String) {
-    private val directory = File(dir)
+import java.io.InputStream
 
-    fun files() : MutableList<File> {
-        val retfiles = mutableListOf<File>()
+class Filemanager(private val dir: String, private val name: String) {
+    private val directory = File(dir)
+    private val filepath = File("$dir/$name")
+    private val listfiles = mutableListOf<File>()
+    init {
         for (f in directory.listFiles()!!) {
             if (f.extension == "txt" || f.extension == "md") {
-                retfiles.add(f)
+                listfiles.add(f)
             }
         }
-        return retfiles
     }
 
+    //returns list of files
+    fun files() : MutableList<File> {
+        return listfiles
+    }
+
+
+    // create and write to that file
+    fun writefile(line:String) {
+        filepath.writeText(line)
+    }
+
+    // opens and read the existing file
+    fun openfile(): String {
+        if (listfiles.contains(filepath)) {
+            return ""
+        }
+        val inputStream: InputStream = filepath.inputStream()
 
-    fun createfile() {
-        //TODO: Create File
+        return inputStream.bufferedReader().use { it.readText() }
     }
 
-    fun deletefile(path:String) {
-        //TODO: DELETE FILE
+    fun deletefile():Boolean {
+        return filepath.delete()
     }
 
 }
\ No newline at end of file
-- 
GitLab