How can I safely encode a string in Java to use as a filename?

后端 未结 9 2021
失恋的感觉
失恋的感觉 2020-11-29 22:53

I\'m receiving a string from an external process. I want to use that String to make a filename, and then write to that file. Here\'s my code snippet to do this:



        
9条回答
  •  一生所求
    2020-11-29 23:15

    Pick your poison from the options presented by commons-codec, example:

    String safeFileName = DigestUtils.sha1(filename);
    

提交回复
热议问题