Intellij idea 从VirtualFile读取文件内容-intellij插件开发
如何从Intellij idea 从VirtualFile读取文件内容-intellij插件开发,intellij-idea,intellij-14,intellij-plugin,Intellij Idea,Intellij 14,Intellij Plugin,如何从虚拟文件读取文件内容。我目前正在使用这种方式 BufferedReader br = new BufferedReader(new InputStreamReader(virtualFile.getInputStream())); String currentLine; StringBuilder stringBuilder = new StringBuilder(); while ((currentLine = br
虚拟文件
读取文件内容。我目前正在使用这种方式
BufferedReader br = new BufferedReader(new InputStreamReader(virtualFile.getInputStream()));
String currentLine;
StringBuilder stringBuilder = new StringBuilder();
while ((currentLine = br.readLine()) != null) {
stringBuilder.append(currentLine);
stringBuilder.append("\n");
}
} catch (IOException e1) {
e1.printStackTrace();
return 0;
}
然而,当我打印
stringbuilder
时,我得到了一些乱码字符串 阅读虚拟文件内容的一些常见方法有:
- file.contentsToByteArray()文件
- LoadTextUtil.loadText(文件)
- FileDocumentManager.getInstance().getDocument(文件).get*CharSequence()
- file.contentsToByteArray()文件
- LoadTextUtil.loadText(文件)
- FileDocumentManager.getInstance().getDocument(文件).get*CharSequence()
您可以找到一些更有用的信息。您可以使用VfsUtil.loadText(虚拟文件) 另外,为了确保文件被更新,您可以使用virtualFile.refresh(false,false) 你可以找到一些更有用的信息