简体   繁体   中英

Android - save file to Device's “data” folder

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?

Try this:

ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("filename", Context.MODE_PRIVATE);
File file = new File("/data/filename");

file.mkdirs();

File mFile = new File(file, filename);

try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM