Creating files again
Answered
I'm trying to create a file and have a hard time understanding what exactly I'm doing wrong before I receive null when trying to extract a parent. It's very likely that I'm doing some dumb stuff, so I will clarify the task: I need to create a file in my project root folder and have it visible right away. Maybe I need something completely different. You can see the code below. Thank you!
JSONObject storyJson = constructJsonObject();
ApplicationManager.getApplication().runWriteAction((Runnable) () -> {
File file = new File(".story.json");
try (FileWriter writer = new FileWriter(file)) {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
final JsonNode tree = objectMapper.readTree(storyJson.toJSONString());
writer.write(objectMapper.writeValueAsString(tree));
writer.flush();
final VirtualFile newParent = VfsUtil.createDirectories(file.getParent());
if (newParent != null) {
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
VfsUtilCore.copyFile(this, virtualFile, newParent);
}
} catch (IOException e) {
e.printStackTrace();
}
});
Please sign in to leave a comment.
please show the full source code, so it's clear _where_ this is invoked
Hello, Yann! This is a dialog:
What is