Note: These pages are being reviewed.
Is it safe to programmatically modify a file which is open in the editor?
It is not safe to modify a
getOutputStream) which is open and modified in the editor. In fact, it is not possible: calling
FileObject.lock() will fail. If you modify the
java.io.File (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
Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqModifyOpenFile , that was last modified by NetBeans user Vstejskal on 2010-06-16T13:28:10Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.