都是些简单的方法,记录下
/**
* 生成随机文件名,当前年月日小时分钟秒钟 +五位随机数
*
* @return
*/
public class RandomName {
private static final SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
private static final Random r = new Random();
public static void main(String[] args) {
// 获取随机的五位数
int rannum = r.nextInt(89999) + 10000;
String nowTimeStr = sDateFormat.format(new Date());
System.out.println(nowTimeStr + rannum);
// 输出 202102061615298392
}
}
/**
* 获取输入文件流的扩展名
*
* @return
*/
public class FileExtension{
public static void main(String[] args) {
String fileName = "认真的雪.mp4";
System.out.println(fileName.substring(fileName.lastIndexOf(".")).replace(".", ""));
// mp4
}
}
/**
* 创建目标路径所涉及到的目录,即/testA/testB/testC/A.jpg, 那么 testA testB testC
* 这三个文件夹都得自动创建
*
*/
public class makeDirPath{
public static void main(String[] args) {
File dirPath = new File("D:/image/testA/testB/testC");
if (!dirPath.exists()) {
dirPath.mkdirs();
}
}
}
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。