Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied: File created in .../files

Tags:

android

I'm creating a file in data/data/myPackage/files/ :

file = new File( getFilesDir() + "/file.txt");

I'm absolutely sure that the file is created.
Right after its creation I call:

file.canWrite();

and the result is true.

When I try to use that file
I get: "Permission Denied".
In Eclipse, in DDMS, this file permissions are like:

-rw-------

Can anyone help here?

Thanks

like image 784
Tsimmi Avatar asked Jan 07 '10 17:01

Tsimmi


People also ask

Why do I get permission denied when creating a directory?

Permission Denied When Creating Directory or Writing a File. If you receive an error telling you that you do not have permissions to create a directory or to write a file to a directory then this is likely an indication that your script is attempting to write to a directory that the user running the build does not own.

What happens if Windows denied access to a file or folder?

If you do not have the appropriate permission, you can't access or change files or folders. So if Windows denies your access to a certain file or folder, you get the permission of the file or folder in following steps.

Why does “Access Denied” error appear?

Why does "Access Denied" error appear? The folder ownership has changed; You don't have the appropriate permissions; The file may be encrypted; The file may be corrupted. To fix "Access Denied " folder or file errors, try out the following methods one by one until the problem is solved. Method 1: Get the ownership of the file or folder

How to change permissions on a file or a folder?

If you want to change the permissions on a file or a folder, you should log on the PC as an administrator. Next, click on "Edit" in "Security" tab. And then, choose your name and enable the check boxes of the permissions that you need. File encryption has the ability to protect users' files and folders.


2 Answers

Ensure you have the correct permissions to write to the file. In your manifest file, include this line

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />.
like image 89
Neelesh Gajender Avatar answered Oct 28 '22 06:10

Neelesh Gajender


Easiest way to open the file (and create it at the same time) would be to use the openFileOutput("file.txt", MODE_PRIVATE) method.

This ensures that the file is only readable by your application (the same as you've have at the moment), plus it returns you a FileOutputStream so you can start writing to it.

like image 36
Christopher Orr Avatar answered Oct 28 '22 06:10

Christopher Orr