1.前言
本章是续上一章的内容,上一章我们主要讲了JShell中的根据不同需求查看代码片段的命令,那么本章主要讲述的是对jshell中的代码片段的操作,例如修改、删除代码片段等。
2.代码片段的修改删除命令
2.1 /edit <名称或 id> 修改代码片段
(1) /edit 修改所有输入的代码片段

注意:使用/edit命令时会弹出修改窗口,修改后点击”Accept”按钮保存修改.
(2)/edit <id>修改指定ID的代码片段
(3)/edit <名称> 修改指定名称的代码片段

2.2./drop <名称或 id> 删除代码片段
(1)/drop <id> 删除指定ID的代码片段

(2)/drop <名称> 删除指定名称的代码片段
3.代码片段的输出输入命令
3.1/save [-all|-history|-start] <文件> 将代码片段保存到文件。
(1)/save -all <文件> 将所有代码片段保存到文件中(包括错误代码)

注意:这里不需要考虑磁盘中是否存在code.txt文件,因为该命令会自动帮我们在磁盘相应的地方创建该文件.
(2)/save -histroy <文件> 将所有键入过的内容历史保存到文件(包括命令)
(3)/save -start <文件> 将所有启动的内容历史保存到文件
3.2 /open <file> 输入指定文件中的代码片段到JShell中

4.代码片段重新运行命令
4.1 /? [<command>|<subject>] 获取 jshell 的相关信息

和/help command命令相似
4.2 /! 重新运行上一个代码片段

4.3 /<id> 按 id 重新运行代码片段

4.4/-<n> 重新运行前面的第 n 个代码片段

小结:
本文章主要讲述的是操作jshell的代码片段的命令,我们可以通过这些命令对我们键入在jshell中的一些代码片段进行操作,例如将jshell中的代码保存到我们的磁盘文件中,重新运行某一段代码等,例如我们对我们写过的代码片段进行重复使用.
网友评论