intellij-idea - 从VirtualFile读取文件内容-intellij插件开发

如何从虚拟文件中读取文件内容。我目前正在使用这种方式

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(file).get*CharSequence()

https://stackoverflow.com/questions/39791858/

相关文章:

python - 如何使用 python 从网站上抓取图表?

latex - 删除部分编号但在 LaTeX 的目录中显示编号

haskell - 如何使用 Data.Time.UTCTime 添加分钟到当前时间?

coldfusion - 如何从 Coldfusion 中的结构数组中删除重复项

java - 从测试用例调用 Controller 时,使用自动连线组件测试 Controller

apache-kafka - 监控kafka的UI工具

hibernate - Spring Boot/JPA/Hibernate,如何根据Spring配置

sql - dplyr sql连接

python - 如何清除 PYQTGRAPH 中的 ScatterPlotItem

unity3d - Unity,我应该将我的游戏引擎脚本附加到什么对象