我想在我的 Android 手机上创建一个文本文件并在其中写入一些文本。
当我点击按钮时,它说saved to /data/user/0/com.example.savetotextfile/files/example.txt
但我找不到这些文件夹。
大多数应用程序都位于“设备存储”>“Android”>“数据”中,但我自己创建的应用程序不在那里。
我是否缺少权限?
我不想写入 SD 卡。
public class MainActivity extends AppCompatActivity {
private static final String FILE_NAME = "example.txt";
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editText);
}
public void save(View v) {
String text = editText.getText().toString();
FileOutputStream fos = null;
try {
fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
fos.write(text.getBytes());
editText.getText().clear();
Toast.makeText(this, "Saved to" + getFilesDir() + "/" + FILE_NAME, Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
如果您想查看内部存储中保存的文件,您不能只查看
通过文件管理器。 (请注意,如果您想直接查看,您的手机应该已root)
按照以下步骤查看保存在内部存储器中的文件。
1) 将设备连接到您的笔记本电脑/计算机。
2)打开android studio。
3)现在,在 android studio 的右端,您将选择设备文件管理器。
4)双击数据文件夹,然后再次双击数据文件夹
5)找到您的应用程序的包名称,例如 com.example.yourapp 并双击它。
6) double click on files folder under the package name of your app you want to see the internal storage files.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)