weka.core.Utils.createRelativePath()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(135)

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

Utils.createRelativePath介绍

[英]Converts a File's absolute path to a path relative to the user (ie start) directory.
[中]将文件的绝对路径转换为相对于用户(ie开始)目录的路径。

代码示例

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Converts a File's absolute path to a path relative to the user (ie start)
 * directory. Includes an additional workaround for Cygwin, which doesn't like
 * upper case drive letters.
 * 
 * @param absolute the File to convert to relative path
 * @return a File with a path that is relative to the user's directory
 * @exception Exception if the path cannot be constructed
 */
public static File convertToRelativePath(File absolute) throws Exception {
 File result;
 String fileStr;
 result = null;
 // if we're running windows, it could be Cygwin
 if (File.separator.equals("\\")) {
  // Cygwin doesn't like upper case drives -> try lower case drive
  try {
   fileStr = absolute.getPath();
   fileStr = fileStr.substring(0, 1).toLowerCase() + fileStr.substring(1);
   result = createRelativePath(new File(fileStr));
  } catch (Exception e) {
   // no luck with Cygwin workaround, convert it like it is
   result = createRelativePath(absolute);
  }
 } else {
  result = createRelativePath(absolute);
 }
 return result;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Converts a File's absolute path to a path relative to the user (ie start)
 * directory. Includes an additional workaround for Cygwin, which doesn't like
 * upper case drive letters.
 * 
 * @param absolute the File to convert to relative path
 * @return a File with a path that is relative to the user's directory
 * @exception Exception if the path cannot be constructed
 */
public static File convertToRelativePath(File absolute) throws Exception {
 File result;
 String fileStr;
 result = null;
 // if we're running windows, it could be Cygwin
 if (File.separator.equals("\\")) {
  // Cygwin doesn't like upper case drives -> try lower case drive
  try {
   fileStr = absolute.getPath();
   fileStr = fileStr.substring(0, 1).toLowerCase() + fileStr.substring(1);
   result = createRelativePath(new File(fileStr));
  } catch (Exception e) {
   // no luck with Cygwin workaround, convert it like it is
   result = createRelativePath(absolute);
  }
 } else {
  result = createRelativePath(absolute);
 }
 return result;
}

相关文章