如何使用Runtime.getRuntime().exec程序,实现使用window自带的画图工具打开某一路径线下的图片文件
时间: 2023-03-28 08:03:48 浏览: 125
您可以使用以下代码实现:
```
String imagePath = "C:\\path\\to\\image.jpg";
try {
Runtime.getRuntime().exec("mspaint.exe " + imagePath);
} catch (IOException e) {
e.printStackTrace();
}
```
其中,`imagePath` 是您想要打开的图片文件的路径。`Runtime.getRuntime().exec()` 方法可以在 Java 中执行外部程序,这里我们使用 `mspaint.exe` 打开 Windows 自带的画图工具,并将图片文件作为参数传递给它。
相关问题
如何在jsp页面中实现,根据文件的保存路径,使用window自带得画图工具打开该路径下的图片文件
你可以使用以下代码在jsp页面中实现:
<%
String filePath = "文件路径";
Runtime.getRuntime().exec("mspaint " + filePath);
%>
其中,filePath是你要打开的图片文件的保存路径。这段代码会调用window自带的画图工具打开该路径下的图片文件。
如何在jsp页面中实现,根据文件的保存路径,使用window自带得画图工具打开该路径下的图片文件的功能
可以使用以下代码实现:
```jsp
<%
String filePath = "图片文件路径";
String cmd = "mspaint " + filePath;
Runtime.getRuntime().exec(cmd);
%>
```
其中,`filePath`为图片文件的路径,`cmd`为打开该文件的命令,使用`Runtime.getRuntime().exec(cmd)`方法执行该命令即可打开该图片文件。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)