Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String fullPath = myEditText.getText().toString().trim();
- String folderPath = fullPath.substring ( 0, fullPath.indexOf ( "/" ) );
- String fileName = fullPath.substring ( fullPath.indexOf ( "/" ) + 1 );
- // First Create folder by coding,
- File folder = new File(Environment.getExternalStorageDirectory().toString() + folderPath );
- if (!folder.exists())
- {
- folder.mkdirs();
- }
- // Note: your path must not have recursive folders like myPath1/myPath2/myFile.txt, otherwise you need to create folder in 2 steps.
- // Now creating file
- File file = new File(Environment.getExternalStorageDirectory().toString() + folderPath + fileName );
- if ( !file.exists() )
- {
- success = file.createFile();
- }
- // Now your file is created, you can do writing code now onwards.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement