我有一个执行批处理文件的java项目。我想知道是否可以将普通的java项目更改为spring boot项目。如果是的话,我能知道我大致该怎么做吗?
我已经读过什么是Spring Boot。然而,我完全困惑于如何将其应用到执行批处理文件的 java 类的任务中。
这是我的代码:
RunBatchMain.java
public static void main(String args[])
{
//Run batch file using java
String filePath = "C:/Users/attsuap1/Desktop/test.bat";
try {
Process p = Runtime.getRuntime().exec(filePath);
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
GetResponseMain.java
public static void main(String args[])
{
String filePath = "C:/Users/attsuap1/Desktop/test.bat";
try {
Process p = Runtime.getRuntime().exec(filePath);
p.waitFor();
InputStream in = p.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = -1;
while((c = in.read()) != -1){
baos.write(c);
}
String response = new String(baos.toByteArray());
System.out.println("Response From Batch File : "+response);
int exitVal = p.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
请有人帮助我。太感谢了。
小智 6
是的,这是可能的。您可以首先转到Spring Initializr 页面。您可以在那里生成一个入门项目。下载生成的项目,然后导入到您的 IDE。起始项目包含一个带有 main 方法的示例类。您只需将代码复制粘贴到此处即可开始。
| 归档时间: |
|
| 查看次数: |
17017 次 |
| 最近记录: |