언어 설정

Menu
Sites
Language
How to reference web app root folder for storing files

Hello,

I know how to use tizen.filesystem.resolve() to access public folders like 'documents' but I want to store my files in a folder that is local to my app.

How should I reference a folder located at the root of my app to create a file at 'app root folder/data/mytextfile.txt'?

Thank you for your help.

Edited by: Brock Boland on 17 3월, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

2 댓글
konduri sai swathi
Hi , Try the below code
var documentsDir;
function onsuccess(files) {
  for(var i = 0; i < files.length; i++) {
    console.log("File Name is " + files[i].name); 
  }

  var testFile = documentsDir.createFile("test.txt");

  if (testFile != null) {
    testFile.openStream(
      "w",
      function(fs){
        fs.write("HelloWorld");
        fs.close();
      }, function(e){
        console.log("Error " + e.message);
      }, "UTF-8"
    );
  }
}

function onerror(error) {
  console.log("The error " + error.message + " occurred when listing the files in the selected folder");
}

tizen.filesystem.resolve(
  '/opt/apps/you app Id/data', 
  function(dir){
    documentsDir = dir;
    dir.listFiles(onsuccess, onerror);
  }, function(e){
    console.log("Error" + e.message);
  }, "rw"
);
If you want to create files in 'app root folder/data' then it'll be stored as hidden file but you can access it by specifying the path , else you can save it in any other folder of the app like '/shared/data' .
Yunchan Cho
path of app root folder is like the following format. /opt/usr/apps/[package id] The following path is data directory that can be readable and writable only by web app itself. /opt/usr/apss/[package id]/data The following path is shared data directory that can be readable by every apps and writable only by web app itself. /opt/usr/apss/[package id]/shared/data