I am trying to create a file in the external SD card storage. The file is not getting created. Interestingly, I have copied the create_file() from one of my otherprojects where it is working perfectly.
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(); } }
Final external = Environment.getExternalStorageDirectory(); File appDir = new File(external, "Accel"); File fData = new File(appDir, "Data.txt);