java - 使用默认应用打开名称中包含空格(或 &)的文件
问题描述
我正在尝试打开一个文件,其路径为 C:\Users\kevin\Documents\LIN KED.png(或 C:\Users\kevin\Documents\LIN&KED.png)。文件路径将在linked_file_command 中。
我想在 Windows 上的默认应用程序中打开该文件。我想继续使用linked_file_command 字符串,只是为了有一个变量而不是硬编码的路径。
我尝试了以下方法:
1) system %{cmd /c "start #{linked_file_command}"}
(from https://stackoverflow.com/questions/9476291/how-to-open-file-in-default-application-ruby )
2) system('cmd /c start "" C:\Users\kevin\Documents\LIN KED.png')
(from https://www.ruby-forum.com/topic/209961 )
两者的结果:
Le système ne peut trouver le fichier C:\Users\kevin\Documents\LIN。(系统找不到文件C:\Users\kevin\Documents\LIN)
提前谢谢^.^
解决方案
这应该工作
filePath = "c:\path\to\file name.jpg"
system %{cmd /c "start #{filePath}"}
推荐阅读
- python - 我正在使用 json 和套接字在 python 中创建一个简单的后门,但出现错误
- html - 如何在 vuejs 中创建动画“波浪”效果?
- python - Django / Python - 将图像从 AWS S3 存储桶转换为 Base64?
- android - 是否可以检测 RecyclerView 项目是否到达屏幕顶部?
- excel - 如何修改通过引用传递数组的类的公共数据成员?
- javascript - 在 Electron IPC 中传递对象会产生旧的对象版本
- c# - 如何在 C# 中按国家/地区获取语言
- excel - 如何使用 powershell 修改 Excel COM 中的对象?
- html - 调整浏览器大小时,如何在元素被另一个元素部分覆盖时使元素滚动?(CSS)
- javascript - 整理列表中的重复号码