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


Java File.getCanonicalPath方法代码示例

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


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

示例1: initialize

import java.io.File; //导入方法依赖的package包/类
public void initialize(String rootDirName) throws RuntimeException, IOException {
    String jFluidNativeLibFullName = Platform.getAgentNativeLibFullName(rootDirName, false, null, -1);

    String jFluidNativeLibDirName = jFluidNativeLibFullName.substring(0, jFluidNativeLibFullName.lastIndexOf('/')); // NOI18N

    String checkedPath = ""; // NOI18N   // Needed only for error reporting

    try {
        File rootDir = MiscUtils.checkDirForName(checkedPath = rootDirName);
        MiscUtils.checkDirForName(checkedPath = jFluidNativeLibDirName);
        MiscUtils.checkFile(new File(checkedPath = jFluidNativeLibFullName), false);

        jFluidRootDirName = rootDir.getCanonicalPath();
    } catch (IOException e) {
        throw new IOException("Problem with a required JFluid installation directory or file " + checkedPath, e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ProfilerEngineSettings.java

示例2: getFileText

import java.io.File; //导入方法依赖的package包/类
private static String getFileText(File file) {
	if (file == null) {
		return Strings.get("fileOpenRecentNoChoices");
	} else {
		String ret;
		try {
			ret = file.getCanonicalPath();
		} catch (IOException e) {
			ret = file.toString();
		}
		if (ret.length() <= MAX_ITEM_LENGTH) {
			return ret;
		} else {
			ret = ret.substring(ret.length() - MAX_ITEM_LENGTH + 3);
			int splitLoc = ret.indexOf(File.separatorChar);
			if (splitLoc >= 0) {
				ret = ret.substring(splitLoc);
			}
			return "..." + ret;
		}
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:23,代码来源:OpenRecent.java

示例3: getResourcesFromDirectory

import java.io.File; //导入方法依赖的package包/类
private static Collection<String> getResourcesFromDirectory(
        final File directory,
        final Pattern pattern) {
    final ArrayList<String> retval = new ArrayList<>();
    final File[] fileList = directory.listFiles();
    for (final File file : fileList) {
        if (file.isDirectory()) {
            retval.addAll(getResourcesFromDirectory(file, pattern));
        } else {
            try {
                final String fileName = file.getCanonicalPath();
                final boolean accept = pattern.matcher(fileName).matches();
                if (accept) {
                    retval.add(fileName);
                }
            } catch (final IOException e) {
                throw new Error(e);
            }
        }
    }
    return retval;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:23,代码来源:ResourceList.java

示例4: process

import java.io.File; //导入方法依赖的package包/类
@Override public void process(Commandline args) throws ShellCommandException {
    checkArgsSize(args, 0);

    beginReadTransaction();

    try {
        File outDir = new File(".", "dump");
        if (! outDir.exists()) {
            outDir.mkdir();
        } else if (! outDir.isDirectory()) {
            throw new ShellCommandException("出力先エラー: " + outDir.getCanonicalPath());
        }

        for (UiTypeName typename : SkeltonTefService.instance().uiTypeNames().instances()) {
            dump(outDir, typename);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:21,代码来源:DumpCommand.java

示例5: getFullPathRelateClass

import java.io.File; //导入方法依赖的package包/类
/**
 * 这个方法可以通过与某个类的class文件的相对路径来获取文件或目录的绝对路径。 通常在程序中很难定位某个相对路径,特别是在B/S应用中。
 * 通过这个方法,我们可以根据我们程序自身的类文件的位置来定位某个相对路径。
 * 比如:某个txt文件相对于程序的Test类文件的路径是../../resource/test.txt,
 * 那么使用本方法Path.getFullPathRelateClass("../../resource/test.txt",Test.class)
 * 得到的结果是txt文件的在系统中的绝对路径。
 * 
 * @param relatedPath 相对路径
 * @param cls 用来定位的类
 * @return 相对路径所对应的绝对路径
 * @throws IOException 因为本方法将查询文件系统,所以可能抛出IO异常
 */
public static final String getFullPathRelateClass(String relatedPath, Class<?> cls) {
	String path = null;
	if (relatedPath == null) {
		throw new NullPointerException();
	}
	String clsPath = getPathFromClass(cls);
	File clsFile = new File(clsPath);
	String tempPath = clsFile.getParent() + File.separator + relatedPath;
	File file = new File(tempPath);
	try {
		path = file.getCanonicalPath();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return path;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:29,代码来源:DataUtil.java

示例6: copy

import java.io.File; //导入方法依赖的package包/类
@ApiMethod
public static boolean copy(File srcDir, File srcFile, File dstDir)
{
   try
   {
      String dest = srcFile.getCanonicalPath();
      dest = dest.substring(srcDir.getCanonicalPath().length(), dest.length());
      if (dest.startsWith("/") || dest.startsWith("\\"))
      {
         dest = dest.substring(1, dest.length());
      }

      File dstFile = new File(dstDir, dest);
      return copyFile(srcFile, dstFile);
   }
   catch (Exception ex)
   {
      Lang.rethrow(ex);
   }
   return false;
}
 
开发者ID:wellsb1,项目名称:fort_j,代码行数:22,代码来源:Files.java

示例7: produceAdditionalOutput

import java.io.File; //导入方法依赖的package包/类
public void produceAdditionalOutput() {
    File swanVisualizerExe = visualizerConfig.getVisualizerExe();
    File swivtPresentationSettingsFile = visualizerConfig.getPresentationSettingsDirectory();
    File outputDir = visualizerConfig.getOutputDirectory();
    System.out.println("SWIVT OUT:\n\t" + swanVisualizerExe.getAbsolutePath() + "\n\t" +
            swivtPresentationSettingsFile.getAbsolutePath() + "\n\t" +
            outputDir.getAbsolutePath());
    try {
        String dirSep = File.separator;
        String[] arguments = new String[]{
                swanVisualizerExe.getParentFile().getCanonicalPath() + dirSep,
                swivtPresentationSettingsFile.getCanonicalPath() + dirSep,   // TODO:  + dirSep for Swivt 2.0
                visualizerConfig.getObservationDirectory().getCanonicalPath() + dirSep,
                visualizerConfig.getModelDirectory().getCanonicalPath() + dirSep,
                visualizerConfig.getOutputDirectory().getCanonicalPath() + dirSep
        };
        BBUtils.runExecutable(swanVisualizerExe.getAbsolutePath(), swanVisualizerExe.getParentFile(), arguments);
    } catch (IOException e) {
        throw new RuntimeException("Could not run " + swanVisualizerExe.getAbsolutePath());
    }
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:22,代码来源:SwanVisualizer.java

示例8: testLoggingWrongFileType

import java.io.File; //导入方法依赖的package包/类
@Test
public void testLoggingWrongFileType() throws Exception {
    File log4jFile = createLog4jFile(LOG4J_CONFIG1);
    try {
        // Set path of log4j properties
        String log4jPath = log4jFile.getCanonicalPath();
        setSysSetting(log4jPath);

        // Invoke "private" method :)
        Method method = testElm.getClass().getDeclaredMethod(
                "postConstruct");
        method.setAccessible(true);
        method.invoke(testElm);

    } finally {
        log4jFile.delete();
        resetSysSetting();
    }

}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:21,代码来源:InitializerTest.java

示例9: validateContextPath

import java.io.File; //导入方法依赖的package包/类
private boolean validateContextPath(File appBase, String contextPath) {
    // More complicated than the ideal as the canonical path may or may
    // not end with File.separator for a directory

    StringBuilder docBase;
    String canonicalDocBase = null;

    try {
        String canonicalAppBase = appBase.getCanonicalPath();
        docBase = new StringBuilder(canonicalAppBase);
        if (canonicalAppBase.endsWith(File.separator)) {
            docBase.append(contextPath.substring(1).replace(
                    '/', File.separatorChar));
        } else {
            docBase.append(contextPath.replace('/', File.separatorChar));
        }
        // At this point docBase should be canonical but will not end
        // with File.separator

        canonicalDocBase =
            (new File(docBase.toString())).getCanonicalPath();

        // If the canonicalDocBase ends with File.separator, add one to
        // docBase before they are compared
        if (canonicalDocBase.endsWith(File.separator)) {
            docBase.append(File.separator);
        }
    } catch (IOException ioe) {
        return false;
    }

    // Compare the two. If they are not the same, the contextPath must
    // have /../ like sequences in it
    return canonicalDocBase.equals(docBase.toString());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:HostConfig.java

示例10: linkCount

import java.io.File; //导入方法依赖的package包/类
@Override
String[] linkCount(File file) throws IOException {
  String[] buf = new String[getLinkCountCommand.length];
  System.arraycopy(getLinkCountCommand, 0, buf, 0, 
                   getLinkCountCommand.length);
  buf[getLinkCountCommand.length - 1] = file.getCanonicalPath();
  return buf;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:9,代码来源:HardLink.java

示例11: relativePath

import java.io.File; //导入方法依赖的package包/类
String relativePath(File file) throws IOException {
    String canonicalPath = file.getCanonicalPath();
    if (!canonicalPath.startsWith(sourceDirectory)) {
        throw new IOException(format("the path %s is not a decendent of the basedir %s", canonicalPath, sourceDirectory));
    }
    return canonicalPath.substring(sourceDirectory.length()).replaceAll("^" + quote(File.separator), "");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:MatchPatternsFileFilter.java

示例12: isForbiddenToRead

import java.io.File; //导入方法依赖的package包/类
private boolean isForbiddenToRead (File file, ProtectionDomain protectionDomain)
{
    if (null == protectionDomain) {
        return false;
    }
    try {
        FilePermission filePermission =
                new FilePermission(file.getCanonicalPath(), "read, delete");
        if (protectionDomain.implies(filePermission)) {
            return false;
        }
    } catch (IOException e) {}

    return true;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:DataTransferer.java

示例13: validateCurrentDir

import java.io.File; //导入方法依赖的package包/类
private static void validateCurrentDir(final File directoryToExecuteIn) throws IOException {
  if (directoryToExecuteIn != null) {
    if (!directoryToExecuteIn.exists())
      throw new IOException("Directory does not exist: \"" + directoryToExecuteIn.getCanonicalPath() + '\"');
    if (!directoryToExecuteIn.isDirectory())
      throw new IOException("Path is not a directory: \"" + directoryToExecuteIn.getCanonicalPath() + '\"');
  }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:RuntimeUtils.java

示例14: realpath

import java.io.File; //导入方法依赖的package包/类
public static String realpath(String path) {
    File f = new File(path);
    String ret = null;
    try {
        ret = f.getCanonicalPath();
    } catch (Exception ex) {
        LOG.warn(ex);
    }
    return (ret);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:11,代码来源:FileUtil.java

示例15: getRelativePath

import java.io.File; //导入方法依赖的package包/类
/** Returns the relative path of the first file resolved against the second. */
public static String getRelativePath(File firstFile, File secondFile) throws IOException {
	String canonicalFirstPath = firstFile.getCanonicalPath();
	String canonicalSecondPath = secondFile.getCanonicalPath();

	int minLength = Math.min(canonicalFirstPath.length(), canonicalSecondPath.length());
	int index = 0;
	for (index = 0; index < minLength; index++) {
		if (canonicalFirstPath.charAt(index) != canonicalSecondPath.charAt(index)) {
			break;
		}
	}

	String relPath = canonicalFirstPath;
	int lastSeparatorIndex = canonicalFirstPath.substring(0, index).lastIndexOf(File.separator);
	if (lastSeparatorIndex != -1) {
		String absRest = canonicalSecondPath.substring(lastSeparatorIndex + 1);
		StringBuffer relPathBuffer = new StringBuffer();
		while (absRest.indexOf(File.separator) >= 0) {
			relPathBuffer.append(".." + File.separator);
			absRest = absRest.substring(absRest.indexOf(File.separator) + 1);
		}
		relPathBuffer.append(canonicalFirstPath.substring(lastSeparatorIndex + 1));
		relPath = relPathBuffer.toString();
	}
	return relPath;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:Tools.java


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