Lasso Soft Inc. > Home

[ file->openWriteOnly ]

Method

The [file->openWriteOnly] method can be called on a [file] object to open a file for writing only. If a path is already stored in the [file] object, it can be called with no parameters. It can also be called with a string specifying the path to a file. If it is called with a path to a file, that new path becomes the path for the [file] object, overriding any previous path.

If [file->openWriteOnly] is called with a file path, it can also take an optional boolean parameter that specifies whether or not to create the file if it doesn't already exist. The default is true which means the file will be created if it does not already exist.

  • Syntax
local(f) = file(...)
#f->openWriteOnly

local(f) = file
#f->openWriteOnly('/path/to/file.txt')

local(f) = file
#f->openWriteOnly('/path/to/file.txt', false)
Examples
  • Beginner

Create a new file and put some text in it

The code example below assumes that the file 'test.txt' doesn't exist. The code will create that file and insert the "Is there a problem with the earth's gravitational pull?" into it.

Code

local(my_file) = file('test.txt')
#my_file->doWithClose => {
    #my_file->openWriteOnly
    #my_file->writeString('"Is there a problem with the earth\'s gravitational pull?"')
}

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft