Create files with similar names using Java without overwriting existing file

后端 未结 4 825
忘了有多久
忘了有多久 2021-01-03 05:43

I was wondering if it is possible to create multiple files with similar names, without overwriting the current file.

for example: if I have a file: xyz.txt next tim

4条回答
  •  盖世英雄少女心
    2021-01-03 06:18

    Take a look at the method File.createTempFile()

    To create the new file, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform. If the prefix is too long then it will be truncated, but its first three characters will always be preserved. If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved. Once these adjustments have been made the name of the new file will be generated by concatenating the prefix, five or more internally-generated characters, and the suffix.

提交回复
热议问题