java relativepath_Java Utils.convertToRelativePath方法代码示例

import weka.core.Utils; //导入方法依赖的package包/类

/**

* Resets the Loader object and sets the source of the data set to be the

* supplied File object.

*

* @param file the source file.

* @throws IOException if an error occurs

*/

@Override

public void setSource(File file) throws IOException {

File original = file;

m_structure = null;

setRetrieval(NONE);

if (file == null) {

throw new IOException("Source file object is null!");

}

// try {

String fName = file.getPath();

try {

if (m_env == null) {

m_env = Environment.getSystemWide();

}

fName = m_env.substitute(fName);

} catch (Exception e) {

// ignore any missing environment variables at this time

// as it is possible that these may be set by the time

// the actual file is processed

// throw new IOException(e.getMessage());

}

file = new File(fName);

// set the source only if the file exists

if (file.exists() && file.isFile()) {

if (file.getName().endsWith(

getFileExtension() + FILE_EXTENSION_COMPRESSED)) {

setSource(new GZIPInputStream(new FileInputStream(file)));

} else {

setSource(new FileInputStream(file));

}

} else {

// System.out.println("Looking in classpath....");

// look for it as a resource in the classpath

// forward slashes are platform independent for loading from the

// classpath...

String fnameWithCorrectSeparators = fName

.replace(File.separatorChar, '/');

if (this.getClass().getClassLoader()

.getResource(fnameWithCorrectSeparators) != null) {

// System.out.println("Found resource in classpath...");

setSource(this.getClass().getClassLoader()

.getResourceAsStream(fnameWithCorrectSeparators));

}

}

// }

/*

* catch (FileNotFoundException ex) { throw new

* IOException("File not found"); }

*/

if (m_useRelativePath) {

try {

m_sourceFile = Utils.convertToRelativePath(original);

m_File = m_sourceFile.getPath();

} catch (Exception ex) {

// System.err.println("[AbstractFileLoader] can't convert path to relative path.");

m_sourceFile = original;

m_File = m_sourceFile.getPath();

}

} else {

m_sourceFile = original;

m_File = m_sourceFile.getPath();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值