How to get the memory content of a file?

I'm writing an IDEA plugin, which needs to get the content of a file when it's renamed.

I just use


to get the content. For plain text files, which is working well, but for Java files, it's a little bit different.

Because when I rename a Java file, it will try to also rename the class name inside the file (file content will change), but that code will just get the content before changed.

Is there any way to get the memory content(which has not been persistent to disk yet)?

1 comment
Comment actions Permalink

Not saved content is backed by the com.intellij.openapi.editor.Document class.
Try FileDocumentManager.getInstance().getCachedDocument().getCharsSequence()
See more in javadoc, IntelliJ IDEA Community source code and here:


Please sign in to leave a comment.