gpt4 book ai didi

java - 用于编译和运行 java 东西的 .bat 文件

转载 作者:行者123 更新时间:2023-11-30 09:30:52 24 4
gpt4 key购买 nike

我正在尝试创建两个 bat 文件。一个是c.bat,一个是r.bat

c.bat 只包含:

cls
javac *.java

这将编译所有 .java 文件。

在 r.bat 中我有:

cls
java *

它不会运行类文件。我认为这是因为“java *”行中的 * 转换为“java Class1.class”、“java Class2.class”等等,而它应该只是“java Class1”和“java Class2”。 (没有扩展名)我该怎么做?我刚开始学习这些东西,但在任何地方都找不到正确的答案。

最佳答案

以下循环遍历在 C:\java\stuff 中找到的所有 .java 文件并一个接一个地运行它们。 %%~nf 正在格式化文件名以不显示文件扩展名即 java 类名。如果将 java %%~nf 更改为 echo java %%~nf,您可以准确地看到发生了什么。

cls
for "C:\java\stuff" %%f in (*.java) do (
java %%~nf
)

For : 以下选项可用:

Variable with modifier  Description

%~I Expands %I which removes any surrounding
quotation marks ("").
%~fI Expands %I to a fully qualified path name.
%~dI Expands %I to a drive letter only.
%~pI Expands %I to a path only.
%~nI Expands %I to a file name only.
%~xI Expands %I to a file extension only.
%~sI Expands path to contain short names only.
%~aI Expands %I to the file attributes of file.
%~tI Expands %I to the date and time of file.
%~zI Expands %I to the size of file.
%~$PATH:I Searches the directories listed in the PATH environment
variable and expands %I to the fully qualified name of
the first one found. If the environment variable name is
not defined or the file is not found by the search,
this modifier expands to the empty string.

关于java - 用于编译和运行 java 东西的 .bat 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13090609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com