| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| |
| = DevFaqModifyOpenFile |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| :keywords: Apache NetBeans wiki DevFaqModifyOpenFile |
| :description: Apache NetBeans wiki DevFaqModifyOpenFile |
| :toc: left |
| :toc-title: |
| :syntax: true |
| |
| == 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 `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 link:http://wiki.netbeans.org/DevFaqModifyOpenFile[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. |