本文整理了Java中java.io.File.isAbsolute()
方法的一些代码示例,展示了File.isAbsolute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.isAbsolute()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:isAbsolute
[英]Indicates if this file's pathname is absolute. Whether a pathname is absolute is platform specific. On Android, absolute paths start with the character '/'.
[中]指示此文件的路径名是否为绝对路径名。路径名是否为绝对值取决于平台。在Android上,绝对路径以字符“/”开头。
代码示例来源:origin: libgdx/libgdx
public File getAbsoluteFile () {
if (isAbsolute()) {
return this;
}
if (parent == null) {
return new File(ROOT, name);
}
return new File(parent.getAbsoluteFile(), name);
}
代码示例来源:origin: jenkinsci/jenkins
private static File resolve(File base, String relative) {
File rel = new File(relative);
if(rel.isAbsolute())
return rel;
else
return new File(base.getParentFile(),relative);
}
代码示例来源:origin: thinkaurelius/titan
private static final String getAbsolutePath(final File configParent, String file) {
File storedir = new File(file);
if (!storedir.isAbsolute()) {
String newFile = configParent.getAbsolutePath() + File.separator + file;
log.debug("Overwrote relative path: was {}, now {}", file, newFile);
return newFile;
} else {
log.debug("Loaded absolute path for key: {}", file);
return file;
}
}
代码示例来源:origin: spotbugs/spotbugs
private String makeAbsolute(String possiblyRelativePath) {
if (possiblyRelativePath.contains("://") || possiblyRelativePath.startsWith("http:")
|| possiblyRelativePath.startsWith("https:") || possiblyRelativePath.startsWith("file:")) {
return possiblyRelativePath;
}
if (base == null) {
return possiblyRelativePath;
}
if (new File(possiblyRelativePath).isAbsolute()) {
return possiblyRelativePath;
}
return new File(base.getParentFile(), possiblyRelativePath).getAbsolutePath();
}
代码示例来源:origin: org.apache.ant/ant
private boolean isExistingAbsoluteFile(String name) {
File f = new File(name);
return f.isAbsolute() && f.exists();
}
代码示例来源:origin: gocd/gocd
public static File applyBaseDirIfRelative(File baseDir, File actualFileToUse) {
if (actualFileToUse == null) {
return baseDir;
}
if (actualFileToUse.isAbsolute()) {
return actualFileToUse;
}
if (StringUtils.isBlank(baseDir.getPath())) {
return actualFileToUse;
}
return new File(baseDir, actualFileToUse.getPath());
}
代码示例来源:origin: apache/maven
@Override
public String alignToBaseDirectory( String path, File basedir )
{
String result = path;
if ( path != null && basedir != null )
{
path = path.replace( '\\', File.separatorChar ).replace( '/', File.separatorChar );
File file = new File( path );
if ( file.isAbsolute() )
{
// path was already absolute, just normalize file separator and we're done
result = file.getPath();
}
else if ( file.getPath().startsWith( File.separator ) )
{
// drive-relative Windows path, don't align with project directory but with drive root
result = file.getAbsolutePath();
}
else
{
// an ordinary relative path, align with project directory
result = new File( new File( basedir, path ).toURI().normalize() ).getAbsolutePath();
}
}
return result;
}
代码示例来源:origin: apache/activemq
private void forceRemoveDataFile(DataFile dataFile) throws IOException {
accessorPool.disposeDataFileAccessors(dataFile);
totalLength.addAndGet(-dataFile.getLength());
if (archiveDataLogs) {
File directoryArchive = getDirectoryArchive();
if (directoryArchive.exists()) {
LOG.debug("Archive directory exists: {}", directoryArchive);
} else {
if (directoryArchive.isAbsolute())
if (LOG.isDebugEnabled()) {
LOG.debug("Archive directory [{}] does not exist - creating it now",
directoryArchive.getAbsolutePath());
}
IOHelper.mkdirs(directoryArchive);
}
LOG.debug("Moving data file {} to {} ", dataFile, directoryArchive.getCanonicalPath());
dataFile.move(directoryArchive);
LOG.debug("Successfully moved data file");
} else {
LOG.debug("Deleting data file: {}", dataFile);
if (dataFile.delete()) {
LOG.debug("Discarded data file: {}", dataFile);
} else {
LOG.warn("Failed to discard data file : {}", dataFile.getFile());
}
}
if (dataFileRemovedListener != null) {
dataFileRemovedListener.fileRemoved(dataFile);
}
}
代码示例来源:origin: thinkaurelius/titan
private static String loadAbsoluteDirectoryPath(String name, String prop, boolean mustExistAndBeAbsolute) {
String s = System.getProperty(prop);
if (null == s) {
s = Joiner.on(File.separator).join(System.getProperty("user.dir"), "target", "cassandra", name, "localhost-bop");
log.info("Set default Cassandra {} directory path {}", name, s);
} else {
log.info("Loaded Cassandra {} directory path {} from system property {}", new Object[] { name, s, prop });
}
if (mustExistAndBeAbsolute) {
File dir = new File(s);
Preconditions.checkArgument(dir.isDirectory(), "Path %s must be a directory", s);
Preconditions.checkArgument(dir.isAbsolute(), "Path %s must be absolute", s);
}
return s;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
this.part.write(dest.getPath());
if (dest.isAbsolute() && !dest.exists()) {
// Servlet 3.0 Part.write is not guaranteed to support absolute file paths:
// may translate the given path to a relative location within a temp dir
// (e.g. on Jetty whereas Tomcat and Undertow detect absolute paths).
// At least we offloaded the file from memory storage; it'll get deleted
// from the temp dir eventually in any case. And for our user's purposes,
// we can manually copy it to the requested location as a fallback.
FileCopyUtils.copy(this.part.getInputStream(), Files.newOutputStream(dest.toPath()));
}
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public FilePredicate is(File ioFile) {
if (ioFile.isAbsolute()) {
return hasAbsolutePath(ioFile.getAbsolutePath());
}
return hasRelativePath(ioFile.getPath());
}
代码示例来源:origin: apache/zookeeper
private void doWarnForRelativePath(File file) {
if(file.isAbsolute()) return;
if(file.getPath().substring(0, 2).equals("."+File.separator)) return;
log.warn(file.getPath()+" is relative. Prepend ."
+File.separator+" to indicate that you're sure!");
}
代码示例来源:origin: crashub/crash
public static Path get(java.io.File file) {
String[] names = path(file, 0);
if (file.isAbsolute()) {
return new Absolute(file.isDirectory(), names);
} else {
return new Relative(file.isDirectory(), names);
}
}
代码示例来源:origin: apache/activemq
/**
* Utility method to help find the root directory of the store
*
* @param dir
* @return
*/
public static File findParentDirectory(File dir) {
if (dir != null) {
String dirPath = dir.getAbsolutePath();
if (!dir.isAbsolute()) {
dir = new File(dirPath);
}
while (dir != null && !dir.isDirectory()) {
dir = dir.getParentFile();
}
}
return dir;
}
}
代码示例来源:origin: eclipse-vertx/vert.x
static List<File> extractRoots(File root, List<String> includes) {
return includes.stream().map(s -> {
if (s.startsWith("*")) {
return root.getAbsolutePath();
}
if (s.contains("*")) {
s = s.substring(0, s.indexOf("*"));
}
File file = new File(s);
if (file.isAbsolute()) {
return file.getAbsolutePath();
} else {
return new File(root, s).getAbsolutePath();
}
}).collect(Collectors.toSet()).stream().map(File::new).collect(Collectors.toList());
}
代码示例来源:origin: bytedeco/javacpp
public void addAll(String key, Collection<String> values) {
if (values != null) {
String root = null;
if (key.equals("platform.compiler") || key.equals("platform.sysroot") || key.equals("platform.toolchain") ||
key.equals("platform.includepath") || key.equals("platform.linkpath")) {
root = platformRoot;
}
List<String> values2 = get(key);
for (String value : values) {
if (value == null) {
continue;
}
if (root != null && !new File(value).isAbsolute() &&
new File(root + value).exists()) {
value = root + value;
}
if (!values2.contains(value)) {
values2.add(value);
}
}
}
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
private static File initModuleBuildDir(File moduleBaseDir, Map<String, String> moduleProperties) {
String buildDir = moduleProperties.get(PROPERTY_PROJECT_BUILDDIR);
if (StringUtils.isBlank(buildDir)) {
return null;
}
File customBuildDir = new File(buildDir);
if (customBuildDir.isAbsolute()) {
return customBuildDir;
}
return new File(moduleBaseDir, customBuildDir.getPath());
}
代码示例来源:origin: libgdx/libgdx
public File getAbsoluteFile () {
if (isAbsolute()) {
return this;
}
if (parent == null) {
return new File(ROOT, name);
}
return new File(parent.getAbsoluteFile(), name);
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private String extractDockerFilePath(DockerComposeServiceWrapper mapper, File parentDir) {
if (mapper.requiresBuild()) {
File buildDir = new File(mapper.getBuildDir());
String dockerFile = mapper.getDockerfile();
if (dockerFile == null) {
dockerFile = "Dockerfile";
}
File ret = new File(buildDir, dockerFile);
return ret.isAbsolute() ? ret.getAbsolutePath() : new File(parentDir, ret.getPath()).getAbsolutePath();
} else {
return null;
}
}
代码示例来源:origin: geotools/geotools
/**
* Creates a human readable message that describe the provided {@link File} object in terms of
* its properties.
*
* <p>Useful for creating meaningful log messages.
*
* @param file the {@link File} object to create a descriptive message for
* @return a {@link String} containing a descriptive message about the provided {@link File}.
*/
public static String getFileInfo(final File file) {
final StringBuilder builder = new StringBuilder();
builder.append("Checking file:")
.append(FilenameUtils.getFullPath(file.getAbsolutePath()))
.append("\n");
builder.append("isHidden:").append(file.isHidden()).append("\n");
builder.append("exists:").append(file.exists()).append("\n");
builder.append("isFile").append(file.isFile()).append("\n");
builder.append("canRead:").append(file.canRead()).append("\n");
builder.append("canWrite").append(file.canWrite()).append("\n");
builder.append("canExecute:").append(file.canExecute()).append("\n");
builder.append("isAbsolute:").append(file.isAbsolute()).append("\n");
builder.append("lastModified:").append(file.lastModified()).append("\n");
builder.append("length:").append(file.length());
final String message = builder.toString();
return message;
}
内容来源于网络,如有侵权,请联系作者删除!