我有一个基于java的应用程序,它读取文件并在基于代码镜像的编辑器中显示相同的文件.java代码读取用户选择的文件并将其转换为字符串.然后使用'editor.setvalue'将字符串传递给编辑器.问题是任何硬编码的字符串都显示正常.但如果从文件中读取,那么我会收到错误
Caused by: netscape.javascript.JSException: SyntaxError: Unexpected EOF
Run Code Online (Sandbox Code Playgroud)
我能够正确打印文件,没有问题.
这就是我在java中尝试做的事情.
String sb = FileUtils.readFileToString(file);
webengine.executeScript("editor.setValue('" + sb + "');");
Run Code Online (Sandbox Code Playgroud)
"webengine.executescript"是一种javafx方式,用于调用web引擎中呈现的html可见的javascript函数.
我的代码镜像代码.
<form>
<textarea id="code" name="code">
</textarea>
</form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers : true,
matchBrackets : true,
mode : "text/x-java",
theme : "theme_value",
indentUnit : 4,
gutter: true
});
</script>
Run Code Online (Sandbox Code Playgroud)
我无法理解导致此问题的所有字符.我尝试使用"+"运算符添加两个字符串,并显示添加的字符串.但是,当我在字符串之间插入换行符"\n"时,我开始得到相同的错误.我尝试用新的行替换换行符
,但没有多少帮助,因为它们显示为不会破坏行.