Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. //实际开发中常用的文件命名方式
  2. //获取文件的后缀,然后自己去命名
  3. //首先我们将文件的后缀名分割出来
  4. String suffix=null;
  5. String[] split = fileName.split("\\.");
  6. if (split!=null){
  7. suffix = split[split.length - 1];
  8. }
  9.  
  10. //文件名使用UUID随机数生成,再拼接上我们上面分割出来的后缀名
  11. String uuid = UUID.randomUUID().toString();
  12. String savafileName=uuid +"." +suffix;
  13. //savafileName:1ca30027-2492-4128-95ae-7abc91dac7bc.jpg
  14. System.out.println("savafileName:"+savafileName);
Add Comment
Please, Sign In to add comment