Languages

Menu
Sites
Language
Access to /data folder

I have some problem with access to files in /data folder. 

If I use this path - "/opt/usr/apps/org.example.test/shared/res/input.txt", all will be OK, Ican read data from file. But if I use  app_get_data_path() + "input.txt" - I won't have an error, so fopen will see this file, but I can't load data from it.

So, I have problem only in access, because all will be OK if I change the location. How can I fix this?

Also I have a question about security of files that are in /data folder, because I don't want user to have ability to open and thange them. 

Responses

6 Replies
Anup

Your application has read and write access to it's data folder, so you should be able to read and write there.

Outside apps have no aceess to the data folder of your app, so your files are secure.

You can check this guide for details.

https://developer.tizen.org/development/getting-started/native-application/understanding-tizen-programming/file-system-directory-hierarchy

Illia Lysenko

Thanks for the link!

I use this two strings to open file:

- const char *file = "/opt/usr/apps/org.example.test/shared/res/input.txt";

const char *file = "/opt/usr/apps/org.example.test/data/input.txt";

All is OK in this first case, but I can't read anything from the second file :(

Anup

I think there is a prolem with the way you are creating this file.

/opt/usr/apps/org.example.test/data/input.txt

I have written a sample code for writing and reading from a file in data folder.

It will work, just try it.

        /*write*/
	std::ofstream writeFile;
	writeFile.open ((std::string(app_get_data_path()) + "input.txt").c_str());
	writeFile << "Writing first line.\n";
	writeFile << "Writing second line.\n";
	writeFile.close();

	/*read*/
	std::string line;
	std::ifstream readFile;
	readFile.open((std::string(app_get_data_path()) + "input.txt").c_str());
	while(getline(readFile, line)) {
		dlog_print(DLOG_ERROR, LOG_TAG, "%s", line.c_str());
	}

 

Alex Dem

Hi,
You should be able to read files inside data folder (as proposed above)
fyi; I was able to read with std::fstream  read from /data folder also.
Alexey.

Jeongsu Kim

If you just want to pack input.txt to your app, let it in /res directory. If you want to modify it, then copy it from /res to /data.

 

  1. put "input.txt" to /res directory
  2. check /data directory
  3. If "input.txt" found then go to 5.
  4. copy "input.txt" from /res to /data directory
  5. use "input.txt" from /data directory
Alex Dem

Hi
Yes, looks like  (I did not find)  there is no way to transfer preloaded files into .../packageName/shared/trusted or into .../packageName/data private folders from project (only copy from res ).
Alexey.