Search code examples
intellij-ideaintellij-plugin

How to get VirtualFile from a VirtualFile URL in IntelliJ


I am working on plugin in on IntelliJ.

Now I have a VirtualFile file, I am trying to write file.getUrl() to local file system so that I can get file back when I restart my plugin. But It seems I can not get the VirtualFile from a url?


Solution

  • To find a file by URL, use VirtualFileManager.findFileByUrl() (source). Or keep things simple, store the path and use LocalFileSystem.findFileByPath() as suggested by @vikingsteve.