Actually, I figured solution right after creating this thread :D

final PsiFileFactory factory = PsiFileFactory.getInstance(project);

final PsiFile file = factory.createFileFromText(language, text);

Right. And if you need virtual file by any chance, there is a `com.intellij.testFramework.LightVirtualFile`


I am writing a plugin. I need to save data to a file, and the file can be read.

my plugin saved data should be share on every project, so I think I should save a file located plugin path or idea path, not be active project path.

What I should do? I can't find any solution in the official doc.

When I write code like following

File bookmark = new File("/bookmark.txt");
try {
FileUtil.writeToFile(bookmark, String.format("%s#%s#L%s", projectName, currentFilePath, String.valueOf(currentLineNumber + 1)), true);
} catch (IOException ex) {

It reports permission denied



Hi Qhe.
If you want to serialize the objects, you can use PersistentStateComponent, check this.


If you want to save the file, you should not write absolute paths in File constructor. Try relative paths.


I used PersistentStateComponent, but when I restart ide, data get missing, according to doc, it shouldn't be like this.



Please sign in to leave a comment.