1.21 gigawatts
1.21 gigawatts

Reputation: 17762

Set the file extension of the temp file

In AIR there is the File.createTempFile() method docs.

Is there a way to change the extension?

Code so far:

var webpage:File = File.createTempFile();
webpage.extension = "html"; // Property is read-only

Upvotes: 0

Views: 620

Answers (1)

obscure
obscure

Reputation: 12891

The simple answer is: no.

You're even not able to set the filename by yourself. As soon as you call File.createTempFile(); it will create a file like fla8121.tmp which is composed of the prefix 'fla' a random 4-digit hex number and finally the '.tmp' file extension.

On windows this file will be created in C:\Users\[Username]\AppData\Local\Temp\

If you want to create a temporary file on your own, you need to do it like this:

    var file:File = File.cacheDirectory.resolvePath("test.html");
    var stream:FileStream = new FileStream();
    stream.open(file, FileMode.WRITE);
    stream.writeUTFBytes("<html>This is a test</html>");
    stream.close();

This will create test.html in the same directory as createTempFile()

Upvotes: 1

Related Questions