Skip to content
zeganstyl edited this page Sep 18, 2020 · 1 revision

Files can be accessed through FS object. It delegates whole work to proxy, as other singletons in Thelema.

Each platform has own implementation of IFileSystem interface.

Files can have different locations, so there is different methods to get files. To know posible locations you can see FileLocation. For example:

  • Local location allows you access files as you normaly access files on your desktop OS.
  • Internal gives you ability to access files, contained in JAR archive of your application or files on web-server.

Simple get:

val file = FS.internal("path/to/file/in/jar")
val file2 = FS.local("path/to/local/file")

Note, for absolute path to local files you can use slash / in the begining of the path.

After you got file, you can read it, write, check if it exists and etc. All file functions are provided through IFile interface.

Read file:

file.readText { status, text ->
	println(text)
}

file.readByteData { status, data ->
	println(data.size)
}

As you can see, contents of file can be obtained in only in lambda brackets. Thelema files use asynchronous style to get contents of files. This allows AJAX to be used in browser.

Also you see here status value, received in lambda. With status you can check if content was successfully received or not. Posible status values are listed in NET object

Clone this wiki locally