这是我的示例代码,我的操作系统是mac
@Component
public class HealthFileSystemServiceImpl {
public HealthCommonConf saveYml(HealthCommonConf healthCommonConf) throws IOException {
Files.setOwner(Paths.get(myFilePath), FileSystems.getDefault().getUserPrincipalLookupService().lookupPrincipalByName("root"));
}
}
并且我有此异常消息。
java.nio.file.FileSystemException: /tmp/jmuser/healthService/monitor/Test-Jmsight-id_Test-Health-Name.yml: Operation not permitted
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:100)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileAttributeViews$Posix.setOwners(UnixFileAttributeViews.java:268)
at java.base/sun.nio.fs.UnixFileAttributeViews$Posix.setOwner(UnixFileAttributeViews.java:290)
at java.base/sun.nio.fs.FileOwnerAttributeViewImpl.setOwner(FileOwnerAttributeViewImpl.java:100)
at java.base/java.nio.file.Files.setOwner(Files.java:2163)
我该如何解决?
编辑1.我的跑步环境
在IntelliJ中,我运行我的junit测试文件。
healthTcpConfRepository.findById(1L)
存在。
myFilePath文件已经存在。
@Autowired
private HealthFileSystemServiceImpl healthFileSystemService;
@Test
public void saveConf() throws IOException {
healthFileSystemService.saveYml(healthTcpConfRepository.findById(1L).orElse(null));
}
root# mvn clean test -Dtest={myPackage}.HealthFileSystemServiceImplTest#saveConf
root
执行。