6 comments

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

final PsiFileFactory factory = PsiFileFactory.getInstance(project);

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

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

0
Avatar
Permanently deleted user

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) {
ex.printStackTrace();
}

It reports permission denied

 

0

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

https://www.jetbrains.org/intellij/sdk/docs/basics/persisting_state_of_components.html 

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

0
Avatar
Permanently deleted user

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

 

0

Please sign in to leave a comment.