Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. String fullPath = myEditText.getText().toString().trim();
  2. String folderPath = fullPath.substring ( 0, fullPath.indexOf ( "/" ) );
  3. String fileName = fullPath.substring ( fullPath.indexOf ( "/" ) + 1 );
  4.  
  5. // First Create folder by coding,
  6.  
  7. File folder = new File(Environment.getExternalStorageDirectory().toString() + folderPath );
  8. if (!folder.exists())
  9. {
  10. folder.mkdirs();
  11. }
  12.  
  13. // Note: your path must not have recursive folders like myPath1/myPath2/myFile.txt, otherwise you need to create folder in 2 steps.
  14.  
  15. // Now creating file
  16. File file = new File(Environment.getExternalStorageDirectory().toString() + folderPath + fileName );
  17.  
  18. if ( !file.exists() )
  19. {
  20. success = file.createFile();
  21. }
  22.  
  23. // Now your file is created, you can do writing code now onwards.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement