How to save a PsiFile to project


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?

1 comment


You have to add it to a PsiDirectory. It is answered in SDK docs in the PSI Files section:


Please sign in to leave a comment.