本文整理了Java中cn.hutool.core.io.FileUtil.getName()
方法的一些代码示例,展示了FileUtil.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getName()
方法的具体详情如下:
包路径:cn.hutool.core.io.FileUtil
类名称:FileUtil
方法名:getName
[英]返回文件名
[中]返回文件名
代码示例来源:origin: looly/hutool
/**
* 构造
* @param url URL,允许为空
* @param name 资源名称
*/
public UrlResource(URL url, String name) {
this.url = url;
this.name = ObjectUtil.defaultIfNull(name, (null != url) ? FileUtil.getName(url.getPath()) : null);
}
代码示例来源:origin: looly/hutool
/**
* 构造
* @param url URL,允许为空
* @param name 资源名称
*/
public UrlResource(URL url, String name) {
this.url = url;
this.name = ObjectUtil.defaultIfNull(name, (null != url) ? FileUtil.getName(url.getPath()) : null);
}
代码示例来源:origin: looly/hutool
/**
* 下载文件
*
* @param path 文件路径
* @param outFile 输出文件或目录
*/
@Override
public void download(String path, File outFile) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
download(dir, fileName, outFile);
}
代码示例来源:origin: looly/hutool
/**
* 下载文件
*
* @param path 文件路径
* @param outFile 输出文件或目录
*/
@Override
public void download(String path, File outFile) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
download(dir, fileName, outFile);
}
代码示例来源:origin: looly/hutool
/**
* 文件或目录是否存在
*
* @param path 目录
* @return 是否存在
*/
public boolean exist(String path) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
final List<String> names = ls(dir);
return containsIgnoreCase(names, fileName);
}
代码示例来源:origin: looly/hutool
/**
* 文件或目录是否存在
*
* @param path 目录
* @return 是否存在
*/
public boolean exist(String path) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
final List<String> names = ls(dir);
return containsIgnoreCase(names, fileName);
}
代码示例来源:origin: looly/hutool
@Override
public boolean delFile(String path) {
final String pwd = pwd();
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
cd(dir);
boolean isSuccess;
try {
isSuccess = client.deleteFile(fileName);
} catch (IOException e) {
throw new FtpException(e);
}
cd(pwd);
return isSuccess;
}
代码示例来源:origin: looly/hutool
@Override
public boolean delFile(String path) {
final String pwd = pwd();
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
cd(dir);
boolean isSuccess;
try {
isSuccess = client.deleteFile(fileName);
} catch (IOException e) {
throw new FtpException(e);
}
cd(pwd);
return isSuccess;
}
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param pathBaseClassLoader 相对路径
* @param classLoader {@link ClassLoader}
* @param clazz {@link Class} 用于定位路径
*/
public ClassPathResource(String pathBaseClassLoader, ClassLoader classLoader, Class<?> clazz) {
super((URL) null);
Assert.notNull(pathBaseClassLoader, "Path must not be null");
final String path = normalizePath(pathBaseClassLoader);
this.path = path;
this.name = StrUtil.isBlank(path) ? null : FileUtil.getName(path);
this.classLoader = ObjectUtil.defaultIfNull(classLoader, ClassUtil.getClassLoader());
this.clazz = clazz;
initUrl();
}
// -------------------------------------------------------------------------------------- Constructor end
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param pathBaseClassLoader 相对路径
* @param classLoader {@link ClassLoader}
* @param clazz {@link Class} 用于定位路径
*/
public ClassPathResource(String pathBaseClassLoader, ClassLoader classLoader, Class<?> clazz) {
super((URL) null);
Assert.notNull(pathBaseClassLoader, "Path must not be null");
final String path = normalizePath(pathBaseClassLoader);
this.path = path;
this.name = StrUtil.isBlank(path) ? null : FileUtil.getName(path);
this.classLoader = ObjectUtil.defaultIfNull(classLoader, ClassUtil.getClassLoader());
this.clazz = clazz;
initUrl();
}
// -------------------------------------------------------------------------------------- Constructor end
代码示例来源:origin: cn.hutool/hutool-all
/**
* 构造
* @param url URL,允许为空
* @param name 资源名称
*/
public UrlResource(URL url, String name) {
this.url = url;
this.name = ObjectUtil.defaultIfNull(name, (null != url) ? FileUtil.getName(url.getPath()) : null);
}
代码示例来源:origin: cn.hutool/hutool-all
/**
* 下载文件
*
* @param path 文件路径
* @param outFile 输出文件或目录
*/
@Override
public void download(String path, File outFile) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
download(dir, fileName, outFile);
}
代码示例来源:origin: cn.hutool/hutool-all
/**
* 文件或目录是否存在
*
* @param path 目录
* @return 是否存在
*/
public boolean exist(String path) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
final List<String> names = ls(dir);
return containsIgnoreCase(names, fileName);
}
代码示例来源:origin: cn.hutool/hutool-all
@Override
public boolean delFile(String path) {
final String pwd = pwd();
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
cd(dir);
boolean isSuccess;
try {
isSuccess = client.deleteFile(fileName);
} catch (IOException e) {
throw new FtpException(e);
}
cd(pwd);
return isSuccess;
}
代码示例来源:origin: cn.hutool/hutool-all
/**
* 构造
*
* @param pathBaseClassLoader 相对路径
* @param classLoader {@link ClassLoader}
* @param clazz {@link Class} 用于定位路径
*/
public ClassPathResource(String pathBaseClassLoader, ClassLoader classLoader, Class<?> clazz) {
super((URL) null);
Assert.notNull(pathBaseClassLoader, "Path must not be null");
final String path = normalizePath(pathBaseClassLoader);
this.path = path;
this.name = StrUtil.isBlank(path) ? null : FileUtil.getName(path);
this.classLoader = ObjectUtil.defaultIfNull(classLoader, ClassUtil.getClassLoader());
this.clazz = clazz;
initUrl();
}
// -------------------------------------------------------------------------------------- Constructor end
内容来源于网络,如有侵权,请联系作者删除!