本文整理了Java中java.nio.file.Files.setAttribute()
方法的一些代码示例,展示了Files.setAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.setAttribute()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:setAttribute
暂无
代码示例来源:origin: speedment/speedment
private static void setAttributeHidden(Path path) {
try {
Files.setAttribute(path, "dos:hidden", true);
} catch (final IOException | UnsupportedOperationException e) {
// Ignore. Maybe this is Linux or MacOS
}
}
代码示例来源:origin: SonarSource/sonarqube
private static Path initWorkingDir(ProjectDefinition module) {
File workingDirAsFile = module.getWorkDir();
Path workingDir = workingDirAsFile.getAbsoluteFile().toPath().normalize();
if (SystemUtils.IS_OS_WINDOWS) {
try {
Files.setAttribute(workingDir, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS);
} catch (IOException e) {
LOGGER.warn("Failed to set working directory hidden: {}", e.getMessage());
}
}
return workingDir;
}
代码示例来源:origin: syncany/syncany
protected File createAppDirs(File localDir) throws IOException {
if (localDir == null) {
throw new RuntimeException("Unable to create app dir, local dir is null.");
}
File appDir = new File(localDir, Config.DIR_APPLICATION);
File logDir = new File(appDir, Config.DIR_LOG);
File cacheDir = new File(appDir, Config.DIR_CACHE);
File databaseDir = new File(appDir, Config.DIR_DATABASE);
File stateDir = new File(appDir, Config.DIR_STATE);
appDir.mkdir();
logDir.mkdir();
cacheDir.mkdir();
databaseDir.mkdir();
stateDir.mkdir();
if (EnvironmentUtil.isWindows()) {
Files.setAttribute(Paths.get(appDir.getAbsolutePath()), "dos:hidden", true);
}
return appDir;
}
代码示例来源:origin: syncany/syncany
Files.setAttribute(filePath, "dos:readonly", dosAttrs.isReadOnly());
Files.setAttribute(filePath, "dos:hidden", dosAttrs.isHidden());
Files.setAttribute(filePath, "dos:archive", dosAttrs.isArchive());
Files.setAttribute(filePath, "dos:system", dosAttrs.isSystem());
代码示例来源:origin: syncany/syncany
Files.setAttribute(bFilePath, "dos:readonly", true);
代码示例来源:origin: apache/nifi
FileStore store = Files.getFileStore(file2.toPath());
if (store.supportsFileAttributeView("dos")) {
Files.setAttribute(file2.toPath(), "dos:hidden", true);
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Set a file hidden (on Windows)
*
* @param file
* a {@link java.io.File} object.
* @param hidden
* a boolean.
* @throws java.io.IOException
* @since 4.1
*/
public static void setHidden(File file, boolean hidden) throws IOException {
Files.setAttribute(toPath(file), "dos:hidden", Boolean.valueOf(hidden), //$NON-NLS-1$
LinkOption.NOFOLLOW_LINKS);
}
代码示例来源:origin: dadoonet/fscrawler
Files.setAttribute(currentTestResourceDir.resolve("second.txt"), "lastAccessTime", fileTime);
Files.setAttribute(currentTestResourceDir.resolve("second.txt"), "lastModifiedTime", fileTime);
logger.info(" ---> Creating a new file third.txt");
Files.write(currentTestResourceDir.resolve("third.txt"), "This is a third file".getBytes());
代码示例来源:origin: perlundq/yajsync
@Override
public void setFileMode(Path path, int mode, LinkOption... linkOption) throws IOException
{
Files.setAttribute(path, "unix:mode", mode, linkOption);
}
代码示例来源:origin: com.speedment.generator/generator-core
private static void setAttributeHidden(Path path) {
try {
Files.setAttribute(path, "dos:hidden", true);
} catch (final IOException | UnsupportedOperationException e) {
// Ignore. Maybe this is Linux or MacOS
}
}
代码示例来源:origin: com.perforce/p4java
@Override
public boolean setReadable(final String fileName, final boolean readable,
final boolean ownerOnly) {
try {
Path path = Paths.get(fileName);
Files.setAttribute(path, "dos:readonly", readable);
} catch (IOException e) {
return false;
}
return true;
}
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
/**
* @param file
* @param hidden
* @throws IOException
* @since 4.1
*/
public static void setHidden(File file, boolean hidden) throws IOException {
Files.setAttribute(file.toPath(), "dos:hidden", Boolean.valueOf(hidden), //$NON-NLS-1$
LinkOption.NOFOLLOW_LINKS);
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit.java7
public static void setHidden(File path, boolean hidden) throws IOException {
Path nioPath = path.toPath();
Files.setAttribute(nioPath, "dos:hidden", Boolean.valueOf(hidden), //$NON-NLS-1$
LinkOption.NOFOLLOW_LINKS);
}
代码示例来源:origin: opendedup/sdfs
public void setMode(int mode, boolean propigateEvent) throws IOException {
this.mode = mode;
this.dirty = true;
Path p = Paths.get(this.path);
Files.setAttribute(p, "unix:mode", Integer.valueOf(mode), LinkOption.NOFOLLOW_LINKS);
}
代码示例来源:origin: perlundq/yajsync
public void setLastModifiedTime(Path path, long mtime, LinkOption... linkOption)
throws IOException
{
Files.setAttribute(path, "basic:lastModifiedTime", FileTime.from(mtime, TimeUnit.SECONDS),
linkOption);
}
代码示例来源:origin: org.apache.sshd/sshd-sftp
protected void setFileTime(Path file, String view, String attribute, FileTime value, LinkOption... options) throws IOException {
if (value == null) {
return;
}
if (log.isDebugEnabled()) {
log.debug("setFileTime({})[{}] {}:{}={}", getServerSession(), file, view, attribute, value);
}
Files.setAttribute(file, view + ":" + attribute, value, options);
}
代码示例来源:origin: perlundq/yajsync
@Override
public void setFileMode(Path path, int mode, LinkOption... linkOption) throws IOException
{
//i.e. (mode & 07000) != 0;
boolean requiresUnix = (mode & (FileOps.S_ISUID | FileOps.S_ISGID | FileOps.S_ISVTX)) != 0;
if (requiresUnix) {
throw new IOException("unsupported operation");
}
Set<PosixFilePermission> perms = modeToPosixFilePermissions(mode);
Files.setAttribute(path, "posix:permissions", perms, linkOption);
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api
private static Path initWorkingDir(ProjectDefinition module) {
File workingDirAsFile = module.getWorkDir();
Path workingDir = workingDirAsFile.getAbsoluteFile().toPath().normalize();
if (SystemUtils.IS_OS_WINDOWS) {
try {
Files.setAttribute(workingDir, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS);
} catch (IOException e) {
LOGGER.warn("Failed to set working directory hidden: {}", e.getMessage());
}
}
return workingDir;
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { Windows.class, DosAttributesT.class, Writable.class } )
public void testWindowsIsHidden() throws IOException {
assertThat( Files.isHidden( fileTA() ) ).isFalse();
Files.getFileAttributeView( absTA(), DosFileAttributeView.class ).setHidden( true );
assertThat( Files.isHidden( fileTA() ) ).isTrue();
Files.setAttribute( absTA(), "dos:hidden", false );
assertThat( Files.isHidden( fileTA() ) ).isFalse();
}
代码示例来源:origin: perlundq/yajsync
@Override
public void setGroup(Path path, Group group, LinkOption... linkOption) throws IOException
{
GroupPrincipal principal = getGroupPrincipalFrom(group.name());
if (principal == null) {
setGroupId(path, group.id(), linkOption);
}
Files.setAttribute(path, "unix:group", principal, linkOption);
}
内容来源于网络,如有侵权,请联系作者删除!