![](/img/trans.png)
[英]How to save downloaded file in internal storage in android studio?
[英]Cant find the saved data to text file in internal storage, How to save file in internal storage android studio?
我想在我的 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();
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.