我正在尝试在外部 SD 卡存储中创建一个文件。该文件未创建。有趣的是,我已经从我的其他项目之一复制了 create_file(),它运行良好。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
create_file();
}
private void create_file() {
String pathToExternalStorage = Environment.getExternalStorageDirectory()
.toString();
File appDirectory = new File(pathToExternalStorage + "/" + "Accel");
appDirectory.mkdirs();
String fname = "Data.txt";
File f_data = new File(appDirectory, fname);
try {
if (!f_data.exists()) {
f_data.createNewFile();
Toast.makeText(this, "File Created", Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}