|
Post by Vladimir Musulainen on Oct 23, 2018 13:58:38 GMT
Ruby #writing to the local file begin file_path = Rho::RhoFile.join(Rho::Application.userFolder, 'filename.txt') file = Rho::RhoFile.new(file_path, Rho::RhoFile::OPEN_FOR_WRITE) file.write("===========================================\n") file.write('Hello from Rhodes!') ensure file.close end #reading the whole local file file_path = Rho::RhoFile.join(Rho::Application.userFolder, 'filename.txt') file_content_as_string = Rho::RhoFile.read(file_path)
#reading specified number characters from the local file begin file_path = Rho::RhoFile.join(Rho::Application.userFolder, 'filename.txt') file = Rho::RhoFile.new(file_path, Rho::RhoFile::OPEN_FOR_READ) characters = file.read(150) #read 150 characters from the file ensure file.close end A file can be open in the following modes: - Rho::RhoFile::OPEN_FOR_APPEND
Open a file for output at the end of a file. The file is created if it does not exist. - Rho::RhoFile.OPEN_FOR_READ
Open a file for read-only operations. The file must exist. - Rho::RhoFile.OPEN_FOR_WRITE
Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file. - Rho::RhoFile.OPEN_FOR_READ_WRITE
Open a file for update (both for read and write). The file must exist.
Pay attention to the app has write permissions only in the user folder. Use Rho::Application.userFolder for getting path to the user folder.
|
|