Create a named temp file in Java

I want to be able to create a temporary text file in Java for display on the screen, but using File.createTempFile () does not give me enough control over its name.

Any thoughts here?

+4
source share
1 answer

Why do you need such control over the name of a temporary file?

There is no question in this, you cannot completely control the name of the file generated by createTempFile . If you really need full control, you need to create a regular File .

You might want to use the following:

  • java.io.tmpdir System property for the temporary file directory
  • createNewFile() to check for name conflicts.
  • deleteOnExit()
+7
source

Source: https://habr.com/ru/post/1303868/


All Articles