slash.common.io.Files.removeExtension()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(113)

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

Files.removeExtension介绍

[英]Remove the extension of the given file name, if there is any.
[中]删除给定文件名的扩展名(如果有)。

代码示例

代码示例来源:origin: cpesch/RouteConverter

/**
 * Replace the extension of the given file name with the
 * given extension.
 *
 * @param name      the file name to replace the extension
 * @param extension the new extension for the file name
 * @return the file name with the given extension
 */
public static String setExtension(String name, String extension) {
  name = removeExtension(name);
  name += extension;
  return name;
}

代码示例来源:origin: cpesch/RouteConverter

static String calculateConvertFileName(File file, int index, int maximum, String extension, int fileNameLength) {
  String name = file.getName();
  name = removeExtension(name);
  name = name.substring(0, min(name.length(), fileNameLength));
  if (calculateNumberLength(maximum) > 0) {
    String number = numberToString(index, maximum);
    name = name.substring(0, min(name.length(), fileNameLength - number.length()));
    name += number;
  }
  name = setExtension(name, extension);
  File parentFile = file.getParentFile();
  String path = parentFile != null ? parentFile.getPath() : ".";
  return new File(path, name).getAbsolutePath();
}

代码示例来源:origin: cpesch/RouteConverter

public List<TravelMode> getAvailableTravelModes() {
  List<TravelMode> result = new ArrayList<>();
  if(getProfiles() != null) {
    File[] files = getProfilesDirectory().listFiles(new FilenameFilter() {
      public boolean accept(File dir, String name) {
        return getExtension(name).equals(".brf");
      }
    });
    if (files != null) {
      for (File file : files) {
        result.add(new TravelMode(removeExtension(file.getName())));
      }
    }
  }
  return result;
}

代码示例来源:origin: cpesch/RouteConverter

public List<Category> getCategories() throws IOException {
  List<Category> categories = new ArrayList<>();
  File[] directories = directory.listFiles(new DirectoryFileFilter());
  if(directories != null) {
    for (File subDirectory : directories) {
      if (isPotentialValidLink(subDirectory)) {
        WindowsShortcut shortcut = new WindowsShortcut(subDirectory);
        if (shortcut.isDirectory()) {
          subDirectory = new File(removeExtension(shortcut.getRealFilename()));
        } else
          continue;
      }
      categories.add(new LocalCategory(catalog, subDirectory));
    }
  }
  return categories;
}

代码示例来源:origin: cpesch/RouteConverter

public void downloadElevationDataFor(List<LongitudeAndLatitude> longitudeAndLatitudes, boolean waitForDownload) {
  Set<String> keys = new HashSet<>();
  for (LongitudeAndLatitude longitudeAndLatitude : longitudeAndLatitudes) {
    keys.add(createFileKey(longitudeAndLatitude.longitude, longitudeAndLatitude.latitude));
  }
  Collection<Downloadable> downloadables = new HashSet<>();
  for (String key : keys) {
    Fragment<Downloadable> fragment = dataSource.getFragment(key);
    // fallback as long as .hgt is not part of the keys
    if (fragment == null)
      fragment = dataSource.getFragment(removeExtension(key));
    if (fragment != null && !createFile(fragment.getKey()).exists())
      downloadables.add(fragment.getDownloadable());
  }
  Collection<Download> downloads = new HashSet<>();
  for (Downloadable downloadable : downloadables) {
    downloads.add(download(downloadable));
  }
  if (!downloads.isEmpty() && waitForDownload)
    downloadManager.waitForCompletion(downloads);
}

代码示例来源:origin: cpesch/RouteConverter

String baseName = removeExtension(args[2]);
File target = absolutize(new File(baseName + format.getExtension()));
if (target.exists()) {

相关文章