当前位置: 首页>>代码示例>>Java>>正文


Java File.getCanonicalFile方法代码示例

本文整理汇总了Java中java.io.File.getCanonicalFile方法的典型用法代码示例。如果您正苦于以下问题:Java File.getCanonicalFile方法的具体用法?Java File.getCanonicalFile怎么用?Java File.getCanonicalFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.getCanonicalFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setDocBase

import java.io.File; //导入方法依赖的package包/类
/**
 * Set the document root.
 *
 * @param docBase
 *            The new document root
 *
 * @exception IllegalArgumentException
 *                if the specified value is not supported by this
 *                implementation
 * @exception IllegalArgumentException
 *                if this would create a malformed URL
 */
@Override
public void setDocBase(String docBase) {

	// Validate the format of the proposed document root
	if (docBase == null)
		throw new IllegalArgumentException(sm.getString("resources.null"));

	// Calculate a File object referencing this document base directory
	base = new File(docBase);
	try {
		base = base.getCanonicalFile();
	} catch (IOException e) {
		// Ignore
	}

	// Validate that the document base is an existing directory
	if (!base.exists() || !base.isDirectory() || !base.canRead())
		throw new IllegalArgumentException(sm.getString("fileResources.base", docBase));
	this.absoluteBase = base.getAbsolutePath();
	super.setDocBase(docBase);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:35,代码来源:FileDirContext.java

示例2: getFileForUri

import java.io.File; //导入方法依赖的package包/类
public File getFileForUri(Uri uri) {
    String path = uri.getEncodedPath();
    int splitIndex = path.indexOf(47, 1);
    String tag = Uri.decode(path.substring(1, splitIndex));
    path = Uri.decode(path.substring(splitIndex + 1));
    File root = (File) this.mRoots.get(tag);
    if (root == null) {
        throw new IllegalArgumentException("Unable to find configured root for " + uri);
    }
    File file = new File(root, path);
    try {
        file = file.getCanonicalFile();
        if (file.getPath().startsWith(root.getPath())) {
            return file;
        }
        throw new SecurityException("Resolved path jumped beyond configured root");
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:FileProvider.java

示例3: JDBCClobFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Constructs a new JDBCClobFile instance backed by the given File object
 * using the given encoding to read and write file content.<p>
 *
 * @param file that is to back the new CLOB instance.
 * @param encoding the name of the character encoding used to read and write
 *         character data in the underlying file, as well as to determine
 *         the character length of and character offsets into the underlying
 *         file. Specify null to denote the platform encoding.
 *
 * @throws SQLException if the given encoding is unsupported;
 *         an I/O error occurs, which is possible because the
 *         construction of the canonical pathname may require
 *         file-system queries; a required system property value
 *         cannot be accessed; a security manager exists and its
 *         <code>{@link java.lang.SecurityManager#checkRead}</code>
 *         method denies read access to the file
 */
public JDBCClobFile(File file, String encoding) throws SQLException {

    if (file == null) {
        throw JDBCUtil.nullArgument("file");
    }

    try {
        setEncoding(encoding);

        m_file = file.getCanonicalFile();

        checkIsFile( /*checkExists*/false);

        m_deleteOnFree = false;
    } catch (Exception ex) {
        throw JDBCUtil.sqlException(ex);
    }
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:37,代码来源:JDBCClobFile.java

示例4: getRoot

import java.io.File; //导入方法依赖的package包/类
@Override
public File getRoot(final File file) {
    if(isUNCPath(file.getPath())) {
        // tmp = server\folder;
        File parent = file;
        File previous = null;
        File can;
        try {
            while(parent.getParentFile()!=null) {
                can = parent.getCanonicalFile();
                previous = parent;
                parent = parent.getParentFile();
            }                
        } catch (IOException e) {
            // this occurs when file path is equal the server name : \\server
            // then go to finally and return previous file
        } finally {
            return previous;
        }
    } else {
        return super.getRoot(file);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:WindowsNativeUtils.java

示例5: normalizeFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Normalize java.io.File, that is make sure that returned File has
 * normalized case on Windows; that old Windows 8.3 filename is normalized;
 * that Unix symlinks are not followed; that relative path is changed to 
 * absolute; etc.
 * @param file file to normalize
 * @return normalized file
 */
public static File normalizeFile(File file) {
    Runnable off = Log.internalLog();
    try {
        // taken from org.openide.util.FileUtil
        if (System.getProperty ("os.name").startsWith("Windows")) { // NOI18N
            // On Windows, best to canonicalize.
            try {
                file = file.getCanonicalFile();
            } catch (IOException e) {
                Logger.getLogger(Manager.class.getName()).warning("getCanonicalFile() on file " + file + " failed: " + e);
                // OK, so at least try to absolutize the path
                file = file.getAbsoluteFile();
            }
        } else {
            // On Unix, do not want to traverse symlinks.
            file = new File(file.toURI().normalize()).getAbsoluteFile();
        }
        return file;
    } finally {
        off.run();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:Manager.java

示例6: findPomFile

import java.io.File; //导入方法依赖的package包/类
private static File findPomFile() {
    File file = new File("pom.xml");
    if (!file.exists()) {
        throw new IllegalStateException("The file (" + file + ") does not exist.\n"
                + "This test needs to be run with the working directory " +  POM_DIRECTORY_NAME + ".");
    }
    try {
        file = file.getCanonicalFile();
    } catch (IOException e) {
        throw new IllegalStateException("Could not get cannonical file for file (" + file + ").", e);
    }
    if (!file.getParentFile().getName().equals(POM_DIRECTORY_NAME)) {
        throw new IllegalStateException("The file (" + file + ") is not correct.\n"
                + "This test needs to be run with the working directory " + POM_DIRECTORY_NAME + ".");
    }
    return file;
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:18,代码来源:AbstractClientArquillianTest.java

示例7: scan

import java.io.File; //导入方法依赖的package包/类
private void scan(URL url, ClassLoader loader) throws Exception {
  if (!url.getProtocol().equals("file")) {
    logger.error("Illegal url, currently only file:// url is supported! {}", url);
    return;
  }

  File file = new File(url.toURI());
  file = file.getCanonicalFile();

  if (!scannedFiles.add(file)) {
    return;
  }

  if (!file.exists()) {
    return;
  }

  if (file.isDirectory()) {
    scanDir(file, loader);
  } else {
    scanJar(file, loader);
  }
}
 
开发者ID:wangyuntao,项目名称:reflect,代码行数:24,代码来源:Scanner.java

示例8: compareSourceRoots

import java.io.File; //导入方法依赖的package包/类
protected final boolean compareSourceRoots(String sr1, String sr2) {
    if (sr1.equals(sr2)) {
        return true;
    }
    File f1 = new File(sr1);
    File f2 = new File(sr2);
    if (f1.isDirectory() && f2.isDirectory() ||
        f1.isFile() && f2.isFile()) { // An archive file
        
        if (f1.equals(f2)) {
            return true;
        }
        try {
            f1 = f1.getCanonicalFile();
            f2 = f2.getCanonicalFile();
            return f1.equals(f2);
        } catch (IOException ioex) {}
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ClassBasedBreakpoint.java

示例9: isSubDirectory

import java.io.File; //导入方法依赖的package包/类
private boolean isSubDirectory(File parent, File child){
  try {
    parent = parent.getCanonicalFile();
    child = child.getCanonicalFile();
    File parentFile = child;
    while (parentFile != null){
      if (parent.equals(parentFile)){
        return true;
      }
      parentFile = parentFile.getParentFile();
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
  return false;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:DockerLinuxContainerRuntime.java

示例10: getCanonicalFile

import java.io.File; //导入方法依赖的package包/类
private static File getCanonicalFile(File file) {
    try {
        return file.getCanonicalFile();
    } catch (IOException e) {
        // TODO: What should we do with this exception?
        return null;
    }
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:9,代码来源:ProjectSetupStep.java

示例11: DatabaseFilenameFilter

import java.io.File; //导入方法依赖的package包/类
DatabaseFilenameFilter(String dbNamePath, boolean extras) {

            canonicalFile = new File(dbNamePath);

            try {
                canonicalFile = canonicalFile.getCanonicalFile();
            } catch (Exception e) {}

            dbName     = canonicalFile.getName();
            parent     = canonicalFile.getParentFile();
            extraFiles = extras;
        }
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:13,代码来源:FileUtil.java

示例12: tryGetCanonicalFile

import java.io.File; //导入方法依赖的package包/类
private static File tryGetCanonicalFile(File file) {
    try {
        return file.getCanonicalFile();
    } catch (IOException e) {
        e.printStackTrace();
        return file;
    }
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:9,代码来源:FoldersFragment.java

示例13: getURI

import java.io.File; //导入方法依赖的package包/类
/**
 * Get the URI for the given file.
 */
protected URL getURI(File file)
    throws MalformedURLException {


    File realFile = file;
    try {
        realFile = realFile.getCanonicalFile();
    } catch (IOException e) {
        // Ignore
    }
    return realFile.toURI().toURL();

}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:17,代码来源:WebappClassLoaderBase.java

示例14: getCanonicalFileHard

import java.io.File; //导入方法依赖的package包/类
/**
 * Obtains canonical File from given path. If there is an
 * IOException while processing, will throw IllegalStateException.
 *
 * @throws IllegalStateException
 */
public static File getCanonicalFileHard(final File file) {
  try {
    return file.getCanonicalFile();
  } catch (IOException e) {
    log.fatal("Can not get canonical file for " + file.toString(), e);
    throw makeIllegalStateException(e);
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:15,代码来源:IoUtils.java

示例15: JDBCBlobFile

import java.io.File; //导入方法依赖的package包/类
/**
 *  Constructs a new instance backed by the given File object.
 *
 * @param file used to back this BLOB instance.
 * @param deleteOnFree Assigns whether an attempt to delete the backing file
 *                     is to be made in response to invocation of {@link #free()}.
 * @throws SQLException If an I/O error occurs, which is possible because
 *         the construction of the canonical pathname may require file system
 *         queries; if a required system property value cannot be accessed,
 *         or if a security manager exists and its <code>{@link
 *         java.lang.SecurityManager#checkRead}</code> method denies
 *         read access to the file
 */
public JDBCBlobFile(final File file,
                    boolean deleteOnFree) throws SQLException {

    m_deleteOnFree = deleteOnFree;

    try {
        m_file = file.getCanonicalFile();
    } catch (Exception ex) {
        throw JDBCUtil.sqlException(ex);
    }

    checkIsFile( /*checkExists*/false);
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:27,代码来源:JDBCBlobFile.java


注:本文中的java.io.File.getCanonicalFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。