本文整理了Java中org.scijava.util.FileUtils.shortenPath()
方法的一些代码示例,展示了FileUtils.shortenPath()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.shortenPath()
方法的具体详情如下:
包路径:org.scijava.util.FileUtils
类名称:FileUtils
方法名:shortenPath
[英]Shortens the path to a maximum of 4 path elements.
[中]将路径缩短到最多4个路径元素。
代码示例来源:origin: org.scijava/scijava-common
/**
* Shortens the path to a maximum of 4 path elements.
*
* @param path the path to the file (relative or absolute)
* @return shortened path
*/
public static String shortenPath(final String path) {
return shortenPath(path, DEFAULT_SHORTENER_THRESHOLD);
}
代码示例来源:origin: scijava/scijava-common
/**
* Shortens the path to a maximum of 4 path elements.
*
* @param path the path to the file (relative or absolute)
* @return shortened path
*/
public static String shortenPath(final String path) {
return shortenPath(path, DEFAULT_SHORTENER_THRESHOLD);
}
代码示例来源:origin: scijava/scijava-common
@Test
public void testShortenPath() {
assertEquals("C:\\Documents and Settings\\"
+ "All Users\\Application Data\\Apple Computer\\...\\SC Info.txt",
FileUtils.shortenPath("C:\\Documents and Settings\\All Users"
+ "\\Application Data\\Apple Computer\\iTunes\\SC Info\\SC Info.txt"));
assertEquals("C:\\Documents and Settings\\All Users\\Application Data\\"
+ "Apple Computer\\iTunes\\...\\SC Info.txt", FileUtils.shortenPath(
"C:\\Documents and Settings\\All Users\\"
+ "Application Data\\Apple Computer\\iTunes\\SC Info\\SC Info.txt", 5));
assertEquals("C:\\temp", FileUtils.shortenPath("C:\\temp"));
assertEquals("C:\\1\\2\\3\\4\\...\\test.txt", FileUtils
.shortenPath("C:\\1\\2\\3\\4\\5\\test.txt"));
assertEquals("C:/1/2/test.txt", FileUtils.shortenPath("C:/1/2/test.txt"));
assertEquals("C:/1/2/3/4/.../test.txt", FileUtils
.shortenPath("C:/1/2/3/4/5/test.txt"));
assertEquals("\\\\server\\p1\\p2\\p3\\p4\\...\\p6", FileUtils
.shortenPath("\\\\server\\p1\\p2\\p3\\p4\\p5\\p6"));
assertEquals("\\\\server\\p1\\p2\\p3", FileUtils
.shortenPath("\\\\server\\p1\\p2\\p3"));
assertEquals("http://www.rgagnon.com/p1/p2/p3/.../pb.html", FileUtils
.shortenPath("http://www.rgagnon.com/p1/p2/p3/p4/p5/pb.html"));
}
内容来源于网络,如有侵权,请联系作者删除!