Skip to content
Snippets Groups Projects
Commit 2ce3753f authored by Inseo Kim's avatar Inseo Kim
Browse files

File management has been finished

parent 9a638944
No related branches found
No related tags found
1 merge request!5File management has been finished
Pipeline #83369 passed
......@@ -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())
}
hello world
\ No newline at end of file
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment