How to save a PsiFile to project
Answered
I am using this code to create a PsiFile from some plaintext
public static PsiFile createNewFile(String fileName, String fileExtension, String fileContent, Project project) {
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
final PsiFile file = factory.createFileFromText(fileName + "." + fileExtension, fileContent);
How do i actually save this PsiFile into the current project's root? Or for that matter, save it into any given location within the project's directory structure?
Please sign in to leave a comment.
Hi,
You have to add it to a PsiDirectory. It is answered in SDK docs in the PSI Files section:
https://plugins.jetbrains.com/docs/intellij/psi-files.html#how-do-i-create-a-psi-file