安卓内存读写
安卓对于各自的app都有相应的存储内存空间,在该空间下,没有读写权限限制,可以随意操作读写。
跨过了该区域,就要添加用户读写权限了。
public void getPath(View v) {
String rootPath = "data/data/com.example.iostorage";
editText.setText(rootPath);
editText.setSelection(editText.getText().toString().length());
}
public void readFile(View v) {
try {
File file = new File(editText.getText().toString(), "aa.txt");
if (!file.exists()) {
Toast.makeText(this, "file not find", 1).show();
return;
}
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) != -1) {
String string = new String(buffer, 0, len);
System.out.println(string);
}