×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.751 | Released: 22 Feb 2012, 2:44am | What's New | Download Now

system.TemporaryDirectory

Description:

Used with system.pathForFile to create a path for storing and retrieving files that only need to persist while the application is running. The path is "/tmp".

This property can also be used with other APIs requesting a "baseDirectory" as a parameter (e.g., display.newImage, display.save, media.playSound.

On the Corona Simulator this will be in a sandboxed folder on a per-application basis. You can view the directories and the files by clicking on "Show Project Sandbox" in the Simulator.

Note: This directory may not exist after the application exits.

Syntax:

path = system.pathForFile( filename, system.TemporaryDirectory )

Example:

local path = system.pathForFile( "data.txt", system.TemporaryDirectory )
 
-- io.open opens a file at path. returns nil if no file found
local fh, reason = io.open( path, "r" )
 
if fh then
   -- read all contents of file into a string
   local contents = fh:read( "*a" )
   print( "Contents of " .. path .. "\n" .. contents )
else
   print( "Reason open failed: " .. reason )  -- display failure message in terminal
 
   -- create file because it doesn't exist yet
   fh = io.open( path, "w" )
   
   if fh then
        print( "Created file" )
   else
        print( "Create file failed!" )
   end
   
   local numbers = {1,2,3,4,5,6,7,8,9}
   fh:write( "Feed me data!\n", numbers[1], numbers[2], "\n" )
   
   for _,v in ipairs( numbers ) do 
       fh:write( v, " " )
   end
   
   fh:write( "\nNo more data\n" )
end
 
io.close( fh )

Parameters:

None.

Returns:

userdata
Returns a special userdata constant pointing to the "/tmp" directory. (This is not a string.)

Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Corona SDK 1.0
  • Windows:
    Corona SDK 2.0
  • iOS:
    Corona SDK 1.0
  • Android:
    Corona SDK 2.0

Replies

fstrudelbenoit's picture
fstrudelbenoit
User offline. Last seen 2 days 4 hours ago. Offline
Joined: 27 May 2011

is there any permission to write in the system.TemporaryDirectory on android ?