我正在尝试为Java编程设置VS代码,我已经完成了。然而,有一件事特别困扰我。例如,当我运行下面的代码时,我在TERMINAL选项卡中获得了输出以及许多其他我不想看到的垃圾。如何更改它,以便控制台中唯一的输出是“ Testing ...”?
public class Hello{
public static void main(String[] args){
System.out.println("Testing...");
}
}
运行代码后的输出如下图所示。即使单击其他选项卡,它们也为空,并且即使我删除/隐藏了终端选项卡,每次我重新运行代码时,它都会弹出。
答案 0 :(得分:3)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"args": "",
"console": "internalConsole",
"mainClass": "${file}"
},
]
}
将此添加到您的launch.json
文件中。这里最重要的选项是"console": "internalConsole",
,这会将所有内容输出到 Debug Console 标签,而不是终端。这样看起来会很干净。
答案 1 :(得分:0)
多亏了 tTheSiD 的回答,我找到了一个更简单的答案。要解决它并获得与 tTheSiD 相同的结果,您可以在 vsCode 设置配置用户界面中执行此操作(这种方法也将确保此新设置适用于所有其他 Java 项目)。
转到VsCode设置ui,打开vscode,然后在右上角转到文件->首选项->设置。然后,一旦你在那里,要应用新设置,在搜索设置框中搜索 launch.json,然后向下滚动并将设置更改为:
之后,如果您返回到您的 Java 程序并按 f5,您的“Hello World”应该会在调试控制台中清晰地显示出来(它应该可以像我测试的那样工作,但如果它不起作用,尝试重新启动 vsCode)。
答案 2 :(得分:0)
我想我有比这两个更好的解决方案。只需复制粘贴下面的代码
{
"workbench.colorTheme": "Solarized Dark",
"editor.mouseWheelZoom": true,
"editor.fontSize": 18,
"git.enableSmartCommit": true,
"code-runner.clearPreviousOutput": false,
"editor.snippetSuggestions": "top",
"window.zoomLevel":0,
"workbench.startupEditor": "newUntitledFile",
"code-runner.runInTerminal": false,
"code-runner.runInOutput": true,
"code-runner.saveFileBeforeRun":true,
"type": "c",
"name": "Debug (Launch) - Current File",
"request": "launch",
"args": "",
"console": "internalConsole",
"mainClass": "${file}",
"code-runner.ignoreSelection": true,
"terminal.integrated.tabs.enabled": true,
"json.schemas": [
],
"launch": {
"configurations": [],
"compounds": []
}
}
转到文件>首选项> sereach json.setting > setting.json 编辑并将其粘贴到那里。 “code-runner.runInTerminal”:假, "code-runner.runInOutput": 真, 特别检查这两个,完成所有操作后,您将在“输出”处获得输出。
谢谢