Created a file, It's in memory only, how to save it to disk? Follow
I've got a plugin that creates an xml file and I want that file saved to disk, but I can't seem to find the magic incantation to do so.
This is what I'm doing.
factory = PsiFileFactory.getInstance(project);
xmlFile = (XmlFile)factory.createFileFromText("foobar", XMLLanguage.INSTANCE, docToString(doc));
editorFactory = EditorFactory.getInstance();
psiDocumentManager = PsiDocumentManager.getInstance(project);
xmlEditor = editorFactory.createEditor(psiDocumentManager.getDocument(xmlFile));
FileEditorManager.getInstance(project).openFile(xmlFile.getVirtualFile(), true);
FileDocumentManager.getInstance().saveAllDocuments();
The xml file opens in an editor tab, but no corresponding file is created on disk. Ideally I'd like this to be created in a resource directory of the currently open project.
Please sign in to leave a comment.
> To save the PSI file to disk, use the
PsiDirectory
.add()
method.Ok, how do I obtain this mysterious PsiDirectory object?
com.intellij.psi.impl.file.PsiDirectoryFactory#createDirectory