Revision as of 13:28, 16 June 2010 by Vstejskal (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

Is it safe to programmatically modify a file which is open in the editor?

It is not safe to modify a FileObject (via getOutputStream) which is open and modified in the editor. In fact, it is not possible: calling FileObject.lock() will fail. If you modify the (bypassing the Filesystems API) you may cause a conflict.

If the file is not modified in the editor (easily checkable via DataObject.isModified()) then after your output stream is closed the file will be reloaded with the new contents.

If the file is modified you can make changes to the open editor buffer: use EditorCookie to acquire the Swing Document and make changes through that. It may be considered impolite to then save the file if it was modified before.

Applies to: NetBeans 4.0 and newer

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo