输出的结果是`/D:/Coding/Project/plugin-tool-bench/build/classes/java/main/`不是我预期的`D:/Coding/Project/plugin-tool-bench/build/classes/`
时间: 2023-08-03 20:09:11 浏览: 65
在获取 JAR 文件所在目录时,你可以使用以下代码来获取预期的结果:
```java
String jarPath = YourClassName.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(jarPath, "UTF-8");
String jarDirectory = new File(decodedPath).getParentFile().getParent();
System.out.println(jarDirectory);
```
这段代码中,我们使用`URLDecoder.decode()`方法对路径进行解码,确保以正确的格式获取路径。然后,我们使用`getParentFile()`两次来获取 JAR 文件所在的目录。最后,我们将目录打印出来或进行其他操作。
请注意,这段代码同样假设你想获取当前 JAR 文件所在的目录。如果你想获取其他 JAR 文件的目录,你需要替换`YourClassName`为相应的类名。
相关问题
RuntimeError: Invalid directory "/home/dell/桌面/coding/2022/WX/STF-main/kodim19.png"
引用\[1\]:RuntimeError: NCCL error in: /opt/ conda/ conda-bld/pytorch 1607370117127/work/torch/lib/c10d/ ProcessGroupNCcL.cpp 784, unhandLed system error, NCCL version 2.7.8 。 引用\[2\]:RuntimeError: NCCL error in: /opt/conda/conda-bld/pytorch_1614378083779/work/torch/lib/c10d/ProcessGroupNCCL.cpp:825, unhandled system error, NCCL version 2.7.8 - distributed - PyTorch Forums 4 pytorch等版本不匹配。 引用\[3\]:参考链接:(3条消息) RuntimeError: NCCL error in:XXX,unhandled system error, NCCL version 2.7.8_++加油呀的博客-CSDN博客 2 CPU资源不够 。
根据您提供的错误信息,RuntimeError: Invalid directory "/home/dell/桌面/coding/2022/WX/STF-main/kodim19.png",这个错误是由于指定的目录路径无效导致的。可能是由于路径中包含了非法字符、文件或文件夹不存在、或者没有访问权限等原因引起的。
请您检查一下指定的目录路径是否正确,并确保路径中的文件或文件夹存在,并且您有足够的权限来访问它们。如果路径中包含非法字符,请尝试使用合法的字符命名文件或文件夹。
如果问题仍然存在,请提供更多的上下文信息,以便我能够更准确地帮助您解决问题。
#### 引用[.reference_title]
- *1* *2* *3* [RuntimeError: NCCL error in: /opt/ conda/ conda-bld/pytorch 1607370117127/work/ torch/lib/c10d/Proce](https://blog.csdn.net/m0_49423868/article/details/124075975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
PermissionError: [Errno 13] Permission denied: 'F:/aa/coding-master/sse/cranfieldDocs'
This error message indicates that the program is trying to access a file or directory located at "F:/aa/coding-master/sse/cranfieldDocs" but does not have the necessary permissions to do so.
To resolve this issue, you can try one or more of the following solutions:
1. Check if the file or directory exists and verify the correct path.
2. Check if the program has the necessary permissions to access the file or directory. You may need to change the file or directory permissions or run the program as an administrator.
3. If the file or directory is being used by another application, close the application and try again.
4. If the file or directory is located on a network drive, check if there are any network connectivity issues.
5. Try running the program from a different location, such as a different folder or drive.