java - H2 Embedded db需要通过java更改数据库文件h2db.mv.db的权限
问题描述
我们可以更改h2db.mv.db文件的权限吗?现在设置为664需要通过java代码更改为770。
解决方案
要更改现有文件的权限,您可以使用
Path p = Paths.get("/path/to/h2db.mv.db");
Files.setPosixFilePermissions(p, PosixFilePermissions.fromString("rwxrwx---"));
where/path/to/h2db.mv.db
是文件的绝对或相对路径。
但是,770 不应该用于数据库,数据库文件既不是目录也不是可执行文件。也许你的意思是660,使用PosixFilePermissions.fromString("rw-rw----")
它。
如果您只想使用 Java 代码指定初始权限,则需要在创建数据库之前创建一个具有这些权限的新空文件:
Path p = Paths.get("/path/to/h2db.mv.db");
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-rw----");
if (Files.notExists(p)) {
Files.createFile(p, PosixFilePermissions.asFileAttribute(perms));
}
// Some permissions may be removed by umask during file creation, so
// they need to be set again
Files.setPosixFilePermissions(p, perms);
Connection c = DriverManager.getConnection("jdbc:h2:/path/to/h2db");
将umask
进程0007
的umask 0007
_ 有了这样umask
的新文件就会有权限660
,新的可执行文件和目录也会有权限770
。
推荐阅读
- php - 使用 htaccess 更改动态 url 的问题
- github - 无法通过 API 向分叉存储库发送提交
- azure-data-factory - 管道上传在 Sink 端失败并带有神秘的错误消息
- maven - 在我的 Web 服务器上创建自定义 Maven 存储库
- java - 当我们将应用程序部署为war文件时如何在itext 7转换器属性中设置baseUri
- javascript - 突破代码不起作用。不知道如何做数组
- c++ - 这是存储浮点数的二维动态数组的正确初始化吗?
- sql - 拆分日期范围中的总 datediff 天数不等于非拆分日期范围中的 datediff 天数,为什么?
- c# - 如何修复播放模式后检查器中缺少的音频按钮?
- google-bigquery - BigQuery 中的 Firebase 数据,什么是“stream_id”?