org.apache.commons.io.FilenameUtils.getFullPath()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(345)

本文整理了Java中org.apache.commons.io.FilenameUtils.getFullPath()方法的一些代码示例,展示了FilenameUtils.getFullPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilenameUtils.getFullPath()方法的具体详情如下:
包路径:org.apache.commons.io.FilenameUtils
类名称:FilenameUtils
方法名:getFullPath

FilenameUtils.getFullPath介绍

[英]Gets the full path from a full filename, which is the prefix + path.

This method will handle a file in either Unix or Windows format. The method is entirely text based, and returns the text before and including the last forward or backslash.

C:\a\b\c.txt --> C:\a\b\ 
~/a/b/c.txt  --> ~/a/b/ 
a.txt        --> "" 
a/b/c        --> a/b/ 
a/b/c/       --> a/b/c/ 
C:           --> C: 
C:\          --> C:\ 
~            --> ~/ 
~/           --> ~/ 
~user        --> ~user/ 
~user/       --> ~user/

The output will be the same irrespective of the machine that the code is running on.
[中]从完整文件名(前缀+路径)获取完整路径。
此方法将处理Unix或Windows格式的文件。该方法完全基于文本,并返回前面的文本,包括最后一个向前或向后斜杠。

C:\a\b\c.txt --> C:\a\b\ 
~/a/b/c.txt  --> ~/a/b/ 
a.txt        --> "" 
a/b/c        --> a/b/ 
a/b/c/       --> a/b/c/ 
C:           --> C: 
C:\          --> C:\ 
~            --> ~/ 
~/           --> ~/ 
~user        --> ~user/ 
~user/       --> ~user/

无论代码在哪台机器上运行,输出都是相同的。

代码示例

代码示例来源:origin: simpligility/android-maven-plugin

private String getFullPathWithName( String filename )
{
  return FilenameUtils.getFullPath( filename ) + FilenameUtils.getName( filename );
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public boolean isIgnored(Path path) {
 if (!isInit) {
  throw new IllegalStateException("Called init() first");
 }
 String fullPath = FilenameUtils.getFullPath(path.toAbsolutePath().toString());
 File scmIgnoreFile = new File(fullPath, path.getFileName() + IGNORE_FILE_EXTENSION);
 return scmIgnoreFile.exists();
}

代码示例来源:origin: uber/NullAway

public static Result run(String inPaths, String pkgName)
  throws IOException, ClassHierarchyException, IllegalArgumentException {
 String outPath = "";
 String firstInPath = inPaths.split(",")[0];
 if (firstInPath.endsWith(".jar") || firstInPath.endsWith(".aar")) {
  outPath =
    FilenameUtils.getFullPath(firstInPath)
      + FilenameUtils.getBaseName(firstInPath)
      + MODEL_JAR_SUFFIX;
 } else if (new File(firstInPath).exists()) {
  outPath = FilenameUtils.getFullPath(firstInPath) + DEFAULT_ASTUBX_LOCATION;
 }
 return run(inPaths, pkgName, outPath, DEBUG, VERBOSE);
}
/**

代码示例来源:origin: jmxtrans/jmxtrans

/**
 * Startup the watchdir service.
 */
private void startupWatchdir() throws Exception {
  File dirToWatch;
  if (this.configuration.getProcessConfigDirOrFile().isFile()) {
    dirToWatch = new File(FilenameUtils.getFullPath(this.configuration.getProcessConfigDirOrFile().getAbsolutePath()));
  } else {
    dirToWatch = this.configuration.getProcessConfigDirOrFile();
  }
  // start the watcher
  this.watcher = new WatchDir(dirToWatch, this);
  this.watcher.start();
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testGetFullPath() {
  assertEquals(null, FilenameUtils.getFullPath(null));
  assertEquals("", FilenameUtils.getFullPath("noseperator.inthispath"));
  assertEquals("a/b/", FilenameUtils.getFullPath("a/b/c.txt"));
  assertEquals("a/b/", FilenameUtils.getFullPath("a/b/c"));
  assertEquals("a/b/c/", FilenameUtils.getFullPath("a/b/c/"));
  assertEquals("a\\b\\", FilenameUtils.getFullPath("a\\b\\c"));
  assertEquals(null, FilenameUtils.getFullPath(":"));
  assertEquals(null, FilenameUtils.getFullPath("1:/a/b/c.txt"));
  assertEquals(null, FilenameUtils.getFullPath("1:"));
  assertEquals(null, FilenameUtils.getFullPath("1:a"));
  assertEquals(null, FilenameUtils.getFullPath("///a/b/c.txt"));
  assertEquals(null, FilenameUtils.getFullPath("//a"));
  assertEquals("", FilenameUtils.getFullPath(""));
  assertEquals("C:", FilenameUtils.getFullPath("C:"));
  assertEquals("C:/", FilenameUtils.getFullPath("C:/"));
  assertEquals("//server/", FilenameUtils.getFullPath("//server/"));
  assertEquals("~/", FilenameUtils.getFullPath("~"));
  assertEquals("~/", FilenameUtils.getFullPath("~/"));
  assertEquals("~user/", FilenameUtils.getFullPath("~user"));
  assertEquals("~user/", FilenameUtils.getFullPath("~user/"));
  assertEquals("a/b/", FilenameUtils.getFullPath("a/b/c.txt"));
  assertEquals("/a/b/", FilenameUtils.getFullPath("/a/b/c.txt"));
  assertEquals("C:", FilenameUtils.getFullPath("C:a"));
  assertEquals("C:a/b/", FilenameUtils.getFullPath("C:a/b/c.txt"));
  assertEquals("C:/a/b/", FilenameUtils.getFullPath("C:/a/b/c.txt"));

代码示例来源:origin: neo4j/neo4j

private void compareSnapshotFiles( Set<String> firstSnapshotFileNames, Set<String> secondSnapshotFileNames,
    FileSystemAbstraction fileSystem )
{
  assertThat( format( "Should have %d modified index segment files. Snapshot segment files are: %s",
          NUMBER_OF_INDEXES, firstSnapshotFileNames ), firstSnapshotFileNames,
      hasSize( NUMBER_OF_INDEXES ) );
  for ( String fileName : firstSnapshotFileNames )
  {
    assertFalse( "Snapshot segments fileset should not have files from another snapshot set." +
            describeFileSets( firstSnapshotFileNames, secondSnapshotFileNames ),
        secondSnapshotFileNames.contains( fileName ) );
    String path = FilenameUtils.getFullPath( fileName );
    assertTrue( "Snapshot should contain files for index in path: " + path + "." +
            describeFileSets( firstSnapshotFileNames, secondSnapshotFileNames ),
        secondSnapshotFileNames.stream().anyMatch( name -> name.startsWith( path ) ) );
    assertTrue( format( "Snapshot segment file '%s' should exist.", fileName ),
        fileSystem.fileExists( new File( fileName ) ) );
  }
}

代码示例来源:origin: simpligility/android-maven-plugin

File parentDir = new File( FilenameUtils.getFullPath( parsedDestination ) );
if ( ! parentDir.exists() )

代码示例来源:origin: geotools/geotools

private String getBaseFullName(String path) {
  final String baseName = FilenameUtils.getBaseName(path);
  final String fullPath = FilenameUtils.getFullPath(path);
  return fullPath + File.separatorChar + baseName;
}

代码示例来源:origin: geotools/geotools

/**
   * Return supportFiles (if found) for the specified file
   *
   * @param filePath
   * @return
   */
  public List<File> getSupportFiles(String filePath) {
    List<File> supportFiles = null;
    String parent = FilenameUtils.getFullPath(filePath);
    String mainName = FilenameUtils.getName(filePath);
    String baseName = FilenameUtils.removeExtension(mainName);
    for (String extension : supportingExtensions) {
      String newFilePath = parent + baseName + extension;
      File file = new File(newFilePath);
      if (file.exists()) {
        if (supportFiles == null) {
          supportFiles = new ArrayList<File>();
        }
        supportFiles.add(file);
      }
    }
    return supportFiles;
  }
}

代码示例来源: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;
}

代码示例来源:origin: geotools/geotools

/**
 * Prepares a message with the status of the provided file.
 *
 * @param sourceFile The {@link File} to provided the status message for
 * @return a status message for the provided {@link File} or a {@link NullPointerException} in
 *     case the {@link File}is <code>null</code>.
 */
private static String fileStatus(File sourceFile) {
  if (sourceFile == null) {
    throw new NullPointerException("Provided null input to fileStatus method");
  }
  final StringBuilder builder = new StringBuilder();
  builder.append("Checking file: ")
      .append(FilenameUtils.getFullPath(sourceFile.getAbsolutePath()))
      .append("\n");
  builder.append("exists: ").append(sourceFile.exists()).append("\n");
  builder.append("isFile: ").append(sourceFile.isFile()).append("\n");
  builder.append("canRead: ").append(sourceFile.canRead()).append("\n");
  builder.append("canWrite: ").append(sourceFile.canWrite()).append("\n");
  builder.append("canExecute: ").append(sourceFile.canExecute()).append("\n");
  builder.append("isHidden: ").append(sourceFile.isHidden()).append("\n");
  builder.append("lastModified: ").append(sourceFile.lastModified()).append("\n");
  return builder.toString();
}

代码示例来源:origin: geotools/geotools

/**
 * Creates a human readable message that describe the provided {@link File} object in terms of
 * its properties.
 *
 * <p>
 *
 * <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;
}

代码示例来源:origin: org.javabeanstack/jbs-commons

/**
 * Devuelve el path de un archivo ejemplo c:/carpeta1/subcarpeta1/archivo.txt
 * retorna c:/carpeta1/subcarpeta1/
 * @param file nombre y path del archivo
 * @return el path del archivo
 */
public static String getFullPath(String file){
  return FilenameUtils.getFullPath(file);
}

代码示例来源:origin: org.mule.runtime/mule-module-builders

public static String getMuleAppConfiguration(String muleConfig) {
 String directory = getFullPath(muleConfig);
 String muleAppConfiguration = directory + DEFAULT_CONFIGURATION_RESOURCE;
 return muleAppConfiguration;
}

代码示例来源:origin: geotools/geotools

this.tileIndexStore =
      new PostgisDatastoreWrapper(
          getTileIndexStore(), FilenameUtils.getFullPath(parentLocation));
} else if (Utils.isOracleStore(spi)) {
  this.tileIndexStore =
      new OracleDatastoreWrapper(
          getTileIndexStore(), FilenameUtils.getFullPath(parentLocation));

代码示例来源:origin: alexo/wro4j

/**
 * Similar to {@link FilenameUtils#getFullPath(String)}, but fixes the problem with Windows platform for situations
 * when the path starts with "/" (servlet context relative resources) which are resolved to "\" on windows.
 *
 * @param path
 *          to compute filePath from.
 * @return full path from the provided path.
 */
public static final String getFullPath(final String path) {
 final String fullPath = FilenameUtils.getFullPath(path);
 return replaceWithServletContextSeparatorIfNedded(fullPath);
}

代码示例来源:origin: ro.isdc.wro4j/wro4j-core

/**
 * Similar to {@link FilenameUtils#getFullPath(String)}, but fixes the problem with Windows platform for situations
 * when the path starts with "/" (servlet context relative resources) which are resolved to "\" on windows.
 *
 * @param path
 *          to compute filePath from.
 * @return full path from the provided path.
 */
public static final String getFullPath(final String path) {
 final String fullPath = FilenameUtils.getFullPath(path);
 return replaceWithServletContextSeparatorIfNedded(fullPath);
}

代码示例来源:origin: com.haulmont.cuba/cuba-web

@Nullable
protected String getLocalizedTemplateContent(Resources resources, String defaultTemplateName, String locale) {
  String localizedTemplate = FilenameUtils.getFullPath(defaultTemplateName)
      + FilenameUtils.getBaseName(defaultTemplateName) +
      "_" + locale +
      "." + FilenameUtils.getExtension(defaultTemplateName);
  return resources.getResourceAsString(localizedTemplate);
}

代码示例来源:origin: net.bpelunit/framework

public String getArchiveLocation(String pathToTest) {
  String pathToArchive = FilenameUtils.concat(pathToTest, FilenameUtils
      .getFullPath(fArchive));
  String archiveName = FilenameUtils.getName(fArchive);
  return FilenameUtils.concat(pathToArchive, archiveName);
}

代码示例来源:origin: geotools/geotools

final String path = FilenameUtils.getFullPath(canonicalPath);
final String baseName = FilenameUtils.getBaseName(canonicalPath);
final String histogramPath = path + baseName + "." + "histogram";

相关文章