File
System File object provide set of functions for working with files and folders
Lib.Sys.IO.File.getContent(path) |
Retrieves the content of the file specified by path as a string. |
path - file path location |
Lib.Sys.IO.File.saveContent(path, content) |
Stores content in the file specified by path. |
path - file path location content - file text content |
Lib.Sys.IO.File.getBytes(path) |
Retrieves the binary content of the file specified by path. |
path - file path location |
Lib.Sys.IO.File.saveBytes(path, bytes) |
Stores bytes in the file specified by path in binary mode. |
path - file path location bytes - Bytes object |
Lib.Sys.IO.File.read(path, binary) |
Returns an FileInput handle to the file specified by path. |
path - file path location binary - file type binary or not |
Lib.Sys.IO.File.write(path, binary) |
Returns an FileOutput handle to the file specified by path. |
path - file path location binary - file type binary or not |
Lib.Sys.IO.File.append(path, binary) |
Similar to Lib.Sys.IO.File.write, but appends to the file if it exists instead of overwriting its contents. |
path - file path location binary - file type binary or not |
Lib.Sys.IO.File.copy(srcPath, dstPath) |
Copies the contents of the file specified by srcPath to the file specified by dstPath. |
srcPath - source file path location dstPath - destination file path location |
Examples:
root = Lib.Media.FileSystem.File.applicationStorageDirectory.nativePath
if not Lib.Sys.FileSystem.exists(root) then
Lib.Sys.FileSystem.createDirectory(root)
end
path = root.."/README.txt"
Lib.Sys.IO.File.saveContent(path, "A SiMpLe FiLe")
if Lib.Media.System.systemName() == "ios" then
Lib.Media.FileSystem.File.new(path).preventBackup = true
end
ba = Lib.Media.Utils.ByteArray.fromBytes(Lib.Sys.IO.File.getBytes(path))
print("length: " .. ba.length)
dkdkd = ba.asString()
print("file contents: " .. dkdkd)
ba.writeUTFBytes("MODIFIED FILE ///////////////////////")
print("now writing as another file and re-reading")
Lib.Sys.IO.File.saveBytes(path, ba)
ba2 = Lib.Media.Utils.ByteArray.fromBytes(Lib.Sys.IO.File.getBytes(path))
print("length: " .. ba2.length)
dkdkd2 = ba2.asString()
print("file contents: " .. dkdkd2)
Created with the Personal Edition of HelpNDoc: Easy EPub and documentation editor