Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 commons-compress TarArchiveEntry 中,可以使用 getMode() 请求模式,但这会返回一个 int。
检查是否设置了任何执行位(用户、组、每个人)的最佳方法是什么?
它可以一次性完成,一次检查所有三个位:
static boolean isExecutable(int mode) { return (mode & 0111) != 0; }
八进制文字在哪里0111,这是非常罕见的,因此作为一种更清晰但更长的替代方案:
0111
static boolean isExecutable(int mode) { int mask = 1 | (1 << 3) | (1 << 6); return (mode & mask) != 0; }