0

I need to save some files in the device's "data" folder, because some other application needs them.

I've tried

new File("/data/filename").createNewFile();

but I get

java.io.IOException: open failed: ENOENT (No such file or directory)

Is the path I'm using wrong?

diego10
  • 81
  • 2
  • 11
  • Check this http://stackoverflow.com/questions/5627353/how-to-create-file-directories-and-folders-in-android-data-data-project-filesyst – Raghavendra Dec 08 '15 at 10:07
  • Possible duplicate of [Where does the file get saved using "File file = new file(filename)" in Android](http://stackoverflow.com/questions/33754141/where-does-the-file-get-saved-using-file-file-new-filefilename-in-android) – MurugananthamS Dec 08 '15 at 10:24

3 Answers3

0

Try this:

ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("filename", Context.MODE_PRIVATE);
mjp66
  • 4,214
  • 6
  • 26
  • 31
MurugananthamS
  • 2,395
  • 4
  • 20
  • 49
0
File file = new File("/data/filename");

file.mkdirs();

File mFile = new File(file, filename);

try this

Hitesh Bhalala
  • 2,872
  • 23
  • 40
0

Are you talking about the data folder in root? Then the device must be rooted and you need root permission.

Arnav M.
  • 2,590
  • 1
  • 27
  • 44