title: I can´t copy my MP3 file from raw to external storage in android
body: <p>I want copy a mp3 file to external storage, that i can share it over whatsapp or something like that. </p>
  
  <p>I get some issues:</p>
  
  <p>java.io.FileNotFoundException: /storage/emulated/0/Music/Arno lacht. (Is a directory)</p>
  
  <p>How i can create a file? Im new in programming sry...</p>
  
  <p>@Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);</p>
  
  <pre><code>    switch (requestCode){
          case MY_PERMISSIONS_REQUEST_WRITE_EXTERNALSTORAGE:{
  
              // If request is cancelled, the result arrays are empty.
              if (grantResults.length &gt; 0
                      &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  
                  // permission was granted, yay! Do the
                  // contacts-related task you need to do.
  
  
                  //  External Storage accessible?
  
                  String state = Environment.getExternalStorageState();
                  if (Environment.MEDIA_MOUNTED.equals(state)) {
  
                      try{
  
                          // Create path
  
  
                          File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) ;
  
  
  
                              File root = new File(path, "Sounds");
  
                              if(!root.exists()) {
                                  // Create new directory
  
                                  root.mkdirs();
                                  Toast.makeText(getApplicationContext(), "Ordner wurde erstellt", Toast.LENGTH_SHORT).show();
                              }
  
  
  
                          // Make sure the music directory exists.
  
  
  
                          File file = new File(root, soundNamenArray.get(itemPosition) );
  
                          // Copy data from internal memory to external memory
  
                          InputStream is = getResources().openRawResource(soundId[itemPosition]);
  
                          FileOutputStream os = new FileOutputStream(file);
  
                          byte[] data = new byte[is.available()];
  
                          int length;
  
                          while (( length = is.read(data)) &gt; 0){
                              os.write(data, 0, length);
  
                          }
  
                          is.close();
                          os.close();
  
  
                          Toast.makeText(getApplicationContext(), "Datei kopiert!", Toast.LENGTH_SHORT).show();
  
  
  
                          uri = Uri.fromFile(file);
  
                      }catch (IOException e){
                          e.printStackTrace();
                          Toast.makeText(getApplicationContext(), "Exception geworfen", Toast.LENGTH_SHORT).show();
  
                      }
  
  
  
  
                      // Intent zum verschicken Starten
                      teilenIntent = new Intent(Intent.ACTION_SEND);
                      teilenIntent.setType("audio/mp3");
                      teilenIntent.putExtra(Intent.EXTRA_STREAM, uri);
                      startActivity(Intent.createChooser(teilenIntent, "Sound teilen"));  
  
  
                  }else {
                      Toast.makeText(getApplicationContext(), "Fehler", Toast.LENGTH_SHORT).show();
                  }
  
  
  
              } else {
  
                  // permission denied, boo! Disable the
                  // functionality that depends on this permission.
              }
              return;
          }
  
          // other 'case' lines to check for other
          // permissions this app might request.
  
  
  
      }
  }
  </code></pre>