1.前言
VSCode需要配置好Java环境,配置链接按官网教程即可:Getting Started with Java in Visual Studio Code
VSCode目录./vscode下文件说明如下:
setting.json : 配置vscode编辑器特性配置,同时基础Java Project中,setting.json会配置项目信息的源文件文件夹、编译字节码文件输出文件夹、第三方依赖jar包引用文件夹,详见:Visual Studio Code User and Workspace Settings
launch.json : 配置程序启动或调试(run or debug)等特性,具体有项目执行主类或入口、程序参数、控制台等其他特性,详见:Run and Debug Java in Visual Studio Code
2.自定义输入流
2.1控制台输入
2.1.1控制台内嵌输入
launch.json文件如下:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Main",
"request": "launch",
"mainClass": "Main", //main程序类名
"projectName": "ACRunning_2db88697",
"vmArgs": "-Xint", //虚拟机参数
"console": "internalConsole", //默认控制台内嵌
}
]
}
效果:
2.1.2命令行外嵌输入
launch.json文件如下:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Main",
"request": "launch",
"mainClass": "Main", //main程序类名
"projectName": "ACRunning_2db88697",
"vmArgs": "-Xint", //虚拟机参数
"console": "externalTerminal", //不支持程序参数,文件输入流
}
]
}
2.2自定义文件输入流
launch.json文件如下:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Main",
"request": "launch",
"mainClass": "Main",
"projectName": "ACRunning_2db88697",
"vmArgs": "-Xint",
"args": " < ${fileDirname}/input",
}
]
}
效果如下:
3.总结
编写算法时,往往输入须提前设置好,如果使用输入文件重定向为输入流时,方便调试输入,查看输出。综合两种方法,更喜欢2.1.2命令行外嵌形式和输入文件重定向输入流方式。太爱了~
附录:
VSCode的terminal形式选择多样性,ctrl+shifp+p选择select default proile, 常用cmd\powershell等。
cmd和powershell区别: