VirtualFile is not refreshed


I have been implementing copy/paste clipboard feature over some kind of node that contains virtualFile field. The problem is when I try to paste a copy, I need to copy file content as well, but for a some reason it caches the old file content. 

The files are changed via Editor.
No one way I found to refresh the virtual files does not work:

LocalFileSystem.getInstance().refreshFiles(listOf(virtualFile), false, false)
virtualFile.refresh(false , false)

These files are created out of Project the following way:

val file = File("${pluginDir.path}${fileSeparator}${}.${extension}")
if (!file.exists()) {

return LocalFileSystem.getInstance().findFileByNioFile(

Could you please help, should I refresh it somehow else or the issue is in wrong VirtualFile creation?

1 comment

found the working way to read actual data:

val file = PsiManager.getInstance(project).findFile(virtualFile)!!

var content = file.text.encodeToByteArray()

Please sign in to leave a comment.