質問

What would be a practical use for temporary files (see code below)?

File temp = File.createTempFile("temp-file-name", ".tmp");

Why can't you store the data you would keep in the file in some variables? If the file is (probably) going to be deleted on the program exit (as "temp" implies), why even create them?

An example can be such as when downloading a file, it often appears as a temporary file while the downloading completes.

役に立ちましたか?

解決 2

Aside from the ram versus disk comment above. You may use temp files as precusor files or files about to be processed or served. For example, a server may generate a large PDF for a browser. That PDF file would be stored as a temp file while the (possibly slow) browser downloads the file. Once the communication is complete, the temp file can be destroyed.

他のヒント

The two reasons I know of:

  1. As storage space for large chunks of memory you don't need at the moment, when doing memory-intensive tasks like video editing

  2. A kind of hacky way of interproccess communication

For our little 'imagefilesystem' project (http://code.google.com/p/imagefilesystem/) we actually use the /tmp directory to store the thumbnails we created based upon the images in the local filesystem. So the thumbs were created 'on demand' and were, as the name of /tmp says it itself' temporary of nature so that it didn't create GBs of permanent data.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top