-1

I need to open mp3 file in windows media player in java. getting an error. codes are as follows

File f=new File("D:\\songsmain\\kolaveri.mp3"); // path of the mp3 free
Desktop d1=Desktop.getDesktop();
d1.open(f);
home
  • 12,468
  • 5
  • 46
  • 54
Dee
  • 7
  • 2

1 Answers1

1

Two possible solutions:

1- Don't forget to include :

import java.awt.Desktop;
import java.io.File;

2- Make sure the file exists :

if (f.exists())
   if (Desktop.isDesktopSupported())
     Desktop.getDesktop().open(f); 
Karim
  • 5,298
  • 3
  • 29
  • 35
  • The [exceptions thrown](http://stackoverflow.com/a/9239693/418556) by `Desktop` should reveal 'missing file' & various other things, if handled & reported properly. – Andrew Thompson Feb 12 '12 at 13:50
  • 1
    You're absolutely right, but since he (or she) doesn't tell us what is the error, I suggest the most basic solutions first :) – Karim Feb 12 '12 at 13:52
  • 1
    He? It is best not to presume the sex of a poster. I claim to be 'Andrew', but you can't prove that I'm not really 'Andrea'. ;) – Andrew Thompson Feb 12 '12 at 13:54
  • Hahaha, whatever :P the person who is asking, and to please you, I'm going to edit my previous comment. ;) – Karim Feb 12 '12 at 13:55
  • Thanks man (or human :P) I guess with 30456 reputation, it would be useless if I +1 you too, but I'm still going to do it. – Karim Feb 12 '12 at 14:01
  • the error thrown is IOException:Failed to open file:file path. Error message: Access is denied – Dee Feb 12 '12 at 14:53
  • @Cookiki For what it's worth, comment upvotes don't increase reputation. – kba Apr 09 '12 at 23:16