When developing with Android studio, Test with a real phone and find that the generated files will not be found.
Here is the abbreviated code for the first time I encountered this problem.
public class mainactivity extends appcompatactivity { @ Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (r.layout.activity_main); // Create a file that allows other programs to read try { write fileoutputstream fos = openfileoutput ("ReadAble.txt", mode_world_readable); fos.write ("Data"). GetBytes ()); fos.close (); File path=getfilesdir (); fos = openfileoutput ("WriteAble.txt", context.mode_world_writeable); Fos.write ("Data". GetBytes ()); fos.close (); fos = openfileoutput (" Public.txt ", context.mode_world_writeable| context.mode_world_readable); fos.write ("Data". GetBytes ()); fos.close (); fos = openfileoutput ("Private.txt" , context.mode_private); fos.write ("Data". GetBytes ()); fos.close (); } catch (exception e) { e.printstacktrace (); } }}
1, if the path is not specified, then the generated file will be in the APK installation package, that is, the/data/data/[package name]/files. But open the DDMS, found the data directory point, no display content. This means that there is no permission to access this directory.
2, find the terminal under as, enter the ADB shell, and then assign permissions to the data directory. Using the command chmod 777/data, the result shows that the command is terminated, which means that no permissions are executed.
3. Use Su root to try to change root account without root account.
4, download the 3,601-key root software to the phone, open root.
5, then to terminal in the execution of Su Root, this shows the role is root, then you can send permissions to the folder
6, Chmod-r 777/data, to/data this directory and its subdirectories in the file to assign all permissions.
7, open Ddms, find/data/data/[package name]/inside find the above code generated several TXT file.
This article is from the "Yuangushi" blog, make sure to keep this source http://cm0425.blog.51cto.com/10819451/1936487
Solutions that are not found for files that are generated when you debug a real machine in Android studio