本文整理汇总了Java中java.io.File.isAbsolute方法的典型用法代码示例。如果您正苦于以下问题:Java File.isAbsolute方法的具体用法?Java File.isAbsolute怎么用?Java File.isAbsolute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.isAbsolute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import java.io.File; //导入方法依赖的package包/类
public static void init(String logsPath) throws Exception
{
if (LoggingSettings.getEnabled())
{
String location = LoggingSettings.getLevelFile();
if (location != null)
{
File configFile = Paths.get(logsPath, location).toFile();
if (configFile.exists())
{
File outputPath = Paths.get(LoggingSettings.getLocation()).toFile();
if (!outputPath.isAbsolute())
outputPath = Paths.get(logsPath, LoggingSettings.getLocation()).toFile();
initInternal(configFile, outputPath.toString(), LoggingSettings.getStdOut());
}
else
throw new Exception("Logging config file does not exist.");
}
}
}
示例2: getJavaInitializationString
import java.io.File; //导入方法依赖的package包/类
/** Should create a string insertable to the newly generated source code.
* @return initialization string
*/
public String getJavaInitializationString() {
File value = (File) getValue ();
if (value == null) {
return "null"; // NOI18N
} else {
// [PENDING] not a full escape of filenames, but enough to at least
// handle normal Windows backslashes
if (baseDirectory != null && !value.isAbsolute()) {
return "new java.io.File(" // NOI18N
+ stringify(baseDirectory.getPath())
+ ", " // NOI18N
+ stringify(value.getPath())
+ ")"; // NOI18N
} else {
return "new java.io.File(" // NOI18N
+ stringify(value.getAbsolutePath())
+ ")"; // NOI18N
}
}
}
示例3: isAbsolutePath
import java.io.File; //导入方法依赖的package包/类
/**
* Return true if the local path is an absolute path.
*
* @param systemId The path string
* @return true if the path is absolute
*/
public static boolean isAbsolutePath(String systemId)
{
if(systemId == null)
return false;
final File file = new File(systemId);
return file.isAbsolute();
}
示例4: findInstallArea
import java.io.File; //导入方法依赖的package包/类
private static String findInstallArea() {
String ia = System.getProperty("netbeans.home"); // NOI18N
LOG.log(Level.FINE, "Home is {0}", ia);
String rest = System.getProperty("netbeans.dirs"); // NOI18N
if (rest != null) {
for (String c : rest.split(File.pathSeparator)) {
File cf = new File(c);
if (!cf.isAbsolute() || !cf.exists()) {
LOG.log(Level.FINE, "Skipping non-existent {0}", c);
continue;
}
int prefix = findCommonPrefix(ia, c);
if (prefix == ia.length()) {
LOG.log(Level.FINE, "No change to prefix by {0}", c);
continue;
}
if (prefix <= 3) {
LOG.log(Level.WARNING, "Cannot compute install area. No common prefix between {0} and {1}", new Object[]{ia, c});
} else {
LOG.log(Level.FINE, "Prefix shortened by {0} to {1} chars", new Object[]{c, prefix});
ia = ia.substring(0, prefix);
LOG.log(Level.FINE, "New prefix {0}", ia);
}
}
} else {
LOG.fine("No dirs");
}
return ia;
}
示例5: hasPath
import java.io.File; //导入方法依赖的package包/类
@Override
public FilePredicate hasPath(String s) {
File file = new File(s);
if (file.isAbsolute()) {
return hasAbsolutePath(s);
}
return hasRelativePath(s);
}
示例6: makeFile
import java.io.File; //导入方法依赖的package包/类
File makeFile(final JFileChooser fc, final String filename) {
File selectedFile = null;
// whitespace is legal on Macs, even on beginning and end of filename
if (filename != null && !filename.equals("")) {
final FileSystemView fs = fc.getFileSystemView();
selectedFile = fs.createFileObject(filename);
if (!selectedFile.isAbsolute()) {
selectedFile = fs.createFileObject(fc.getCurrentDirectory(), filename);
}
}
return selectedFile;
}
示例7: findExecutable
import java.io.File; //导入方法依赖的package包/类
public File findExecutable(String executableName)
{
File file = new File(executableName);
if (file.isAbsolute())
{
file = canExecute(file);
}
else
{
file = findExecutableOnPath(executableName);
}
return file;
}
示例8: getSourceFile
import java.io.File; //导入方法依赖的package包/类
static FileObject getSourceFile(String sourcePath, FileObject parentFolder) {
File sourceFile = new File(sourcePath);
FileObject fo;
if (sourceFile.isAbsolute()) {
fo = FileUtil.toFileObject(FileUtil.normalizeFile(sourceFile));
} else {
fo = parentFolder.getFileObject(sourcePath);
}
return fo;
}
示例9: normaliseRelativePath
import java.io.File; //导入方法依赖的package包/类
public static File normaliseRelativePath(File path) {
if (path.isAbsolute()) {return null;}
File parent = path.getParentFile();
String child_name = normaliseRelativePathPart(path.getName());
if (child_name == null) {
return null;
}
// Simple one-level path.
if (parent == null) {
return new File(child_name);
}
ArrayList parts = new ArrayList();
parts.add(child_name);
String filepart = null;
while (parent != null) {
filepart = normaliseRelativePathPart(parent.getName());
if (filepart == null) {return null;}
else if (filepart.length()==0) {/* continue */}
else {parts.add(0, filepart);}
parent = parent.getParentFile();
}
StringBuilder sb = new StringBuilder((String)parts.get(0));
for (int i=1; i<parts.size(); i++) {
sb.append(File.separatorChar);
sb.append(parts.get(i));
}
return new File(sb.toString());
}
示例10: is
import java.io.File; //导入方法依赖的package包/类
@Override
public FilePredicate is(File ioFile) {
if (ioFile.isAbsolute()) {
return hasAbsolutePath(ioFile.getAbsolutePath());
}
return hasRelativePath(ioFile.getPath());
}
示例11: validateFile
import java.io.File; //导入方法依赖的package包/类
@NbBundle.Messages({
"# {0} - source",
"ExternalExecutableValidator.validateFile.missing={0} must be selected.",
"# {0} - source",
"ExternalExecutableValidator.validateFile.notAbsolute={0} must be an absolute path.",
"# {0} - source",
"ExternalExecutableValidator.validateFile.notFile={0} must be a valid file.",
"# {0} - source",
"ExternalExecutableValidator.validateFile.notReadable={0} is not readable.",
"# {0} - source",
"ExternalExecutableValidator.validateFile.notWritable={0} is not writable."
})
@CheckForNull
private static String validateFile(String source, String filePath, boolean writable) {
if (filePath == null
|| filePath.trim().isEmpty()) {
return Bundle.ExternalExecutableValidator_validateFile_missing(source);
}
File file = new File(filePath);
if (!file.isAbsolute()) {
return Bundle.ExternalExecutableValidator_validateFile_notAbsolute(source);
} else if (!file.isFile()) {
return Bundle.ExternalExecutableValidator_validateFile_notFile(source);
} else if (!file.canRead()) {
return Bundle.ExternalExecutableValidator_validateFile_notReadable(source);
} else if (writable && !file.canWrite()) {
return Bundle.ExternalExecutableValidator_validateFile_notWritable(source);
}
return null;
}
示例12: validateFile
import java.io.File; //导入方法依赖的package包/类
/**
* Validate a file path and return {@code null} if it is valid, otherwise an error.
* <p>
* A valid file means that the <tt>filePath</tt> represents a valid, readable file
* with absolute file path.
* @param source source used in error message (e.g. "Script", "Config file")
* @param filePath a file path to validate
* @param writable {@code true} if the file must be writable, {@code false} otherwise
* @return {@code null} if it is valid, otherwise an error
*/
@NbBundle.Messages({
"# {0} - source",
"FileUtils.validateFile.missing={0} must be selected.",
"# {0} - source",
"FileUtils.validateFile.notAbsolute={0} must be an absolute path.",
"# {0} - source",
"FileUtils.validateFile.notFile={0} must be a valid file.",
"# {0} - source",
"FileUtils.validateFile.notReadable={0} is not readable.",
"# {0} - source",
"FileUtils.validateFile.notWritable={0} is not writable."
})
@CheckForNull
public static String validateFile(String source, String filePath, boolean writable) {
if (!StringUtils.hasText(filePath)) {
return Bundle.FileUtils_validateFile_missing(source);
}
File file = new File(filePath);
if (!file.isAbsolute()) {
return Bundle.FileUtils_validateFile_notAbsolute(source);
} else if (!file.isFile()) {
return Bundle.FileUtils_validateFile_notFile(source);
} else if (!file.canRead()) {
return Bundle.FileUtils_validateFile_notReadable(source);
} else if (writable && !file.canWrite()) {
return Bundle.FileUtils_validateFile_notWritable(source);
}
return null;
}
示例13: isRoot
import java.io.File; //导入方法依赖的package包/类
/**
* Determines if the given file is a root in the navigable tree(s).
* Examples: Windows 98 has one root, the Desktop folder. DOS has one root
* per drive letter, <code>C:\</code>, <code>D:\</code>, etc. Unix has one root,
* the <code>"/"</code> directory.
*
* The default implementation gets information from the <code>ShellFolder</code> class.
*
* @param f a <code>File</code> object representing a directory
* @return <code>true</code> if <code>f</code> is a root in the navigable tree.
* @see #isFileSystemRoot
*/
public boolean isRoot(File f) {
if (f == null || !f.isAbsolute()) {
return false;
}
File[] roots = getRoots();
for (File root : roots) {
if (root.equals(f)) {
return true;
}
}
return false;
}
示例14: getAllPossibleValues
import java.io.File; //导入方法依赖的package包/类
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType,
String existingData, String optionContext, MethodTarget target) {
// prefix is needed while comparing Completion Candidates as potential matches
String prefixToUse = "";
boolean prependAbsolute = true;
File parentDir = null; // directory to be searched for file(s)
if (existingData != null) {
// System.out.println("FilePathConverter.getAllPossibleValues() : optionContext ::
// "+optionContext+", existingData : "+existingData);
String[] completionValues = new String[0];
if (ConverterHint.FILE_PATHSTRING.equals(optionContext)) {
// if existingData is empty, start from root
if (existingData != null && existingData.trim().isEmpty()) {
File[] listRoots = File.listRoots();
completionValues = new String[listRoots.length];
for (int i = 0; i < listRoots.length; i++) {
completionValues[i] = listRoots[i].getPath();
}
prefixToUse = File.separator;
} else {
// Create a file from existing data
File file = new File(existingData);
if (file.isDirectory()) {
// For a directory, list files/sub-dirsin the directory
parentDir = file;
completionValues = parentDir.list();
} else if (!file.exists()) {
parentDir = file.getParentFile();
if (parentDir == null) {
try {
parentDir = file.getCanonicalFile().getParentFile();
} catch (IOException e) {
parentDir = null;
}
}
if (parentDir != null) {
completionValues = parentDir.list(new FileNameFilterImpl(parentDir, file.getName()));
}
}
// whether the file path is absolute
prependAbsolute = file.isAbsolute();
}
}
if (completionValues.length > 0) {
// use directory path as prefix for completion of names of the contained files
if (parentDir != null) {
if (existingData.startsWith(".")) { // handle . & ..
prefixToUse = parentDir.getPath();
} else if (prependAbsolute) {
prefixToUse = parentDir.getAbsolutePath();
}
}
// add File.separator in the end
if (!prefixToUse.endsWith(File.separator)
&& (prependAbsolute || existingData.startsWith("."))) {
prefixToUse += File.separator;
}
for (int i = 0; i < completionValues.length; i++) {
completions.add(new Completion(prefixToUse + completionValues[i]));
}
}
}
return !completions.isEmpty();
}
示例15: ensureImports
import java.io.File; //导入方法依赖的package包/类
/**
* Make sure that the custom build script imports the original build script
* and is using the same base dir.
* Used for generated targets which essentially copy Ant targets from build.xml.
* Use with {@link #GENERAL_SCRIPT_PATH}.
* Idempotent, takes effect only once.
* @param antProject XML of an Ant project (document element)
* @oaram origScriptPath Ant name of original build script's path
*/
void ensureImports(Element antProject, String origScriptPath) throws IOException, SAXException {
if (antProject.getAttribute("basedir").length() > 0) {
// Do not do it twice to the same script.
return;
}
String origScriptPathEval = evaluator.evaluate(origScriptPath);
if (origScriptPathEval == null) {
// Can't do anything, forget it.
return;
}
String origScriptURI = Utilities.toURI(helper.resolveFile(origScriptPathEval)).toString();
Document origScriptDocument = XMLUtil.parse(new InputSource(origScriptURI), false, true, null, null);
String origBasedir = origScriptDocument.getDocumentElement().getAttribute("basedir"); // NOI18N
if (origBasedir.length() == 0) {
origBasedir = "."; // NOI18N
}
String basedir, importPath;
File origScript = new File(origScriptPathEval);
if (origScript.isAbsolute()) {
// Use full path.
importPath = origScriptPathEval;
if (new File(origBasedir).isAbsolute()) {
basedir = origBasedir;
} else {
basedir = PropertyUtils.resolveFile(origScript.getParentFile(), origBasedir).getAbsolutePath();
}
} else {
// Import relative to that path.
// Note that <import>'s path is always relative to the location of the importing script, regardless of the basedir.
String prefix = /* ".." times count('/', FILE_SCRIPT_PATH) */"../"; // NOI18N
importPath = prefix + origScriptPathEval;
if (new File(origBasedir).isAbsolute()) {
basedir = origBasedir;
} else {
int slash = origScriptPathEval.replace(File.separatorChar, '/').lastIndexOf('/');
if (slash == -1) {
basedir = prefix + origBasedir;
} else {
basedir = prefix + origScriptPathEval.substring(0, slash + 1) + origBasedir;
}
// Trim:
basedir = basedir.replaceAll("/\\.$", ""); // NOI18N
}
}
antProject.setAttribute("basedir", basedir); // NOI18N
Element importEl = antProject.getOwnerDocument().createElement("import"); // NOI18N
importEl.setAttribute("file", importPath); // NOI18N
antProject.appendChild(importEl);
}