swing - Is it possible to know whether the copied content in clipboard is mp3 file using awt.Toolkit and Clipboard in java -


i trying write code runs @ background , monitors copy actions copying .mp3 file or folder containing .mp3 file

{              clipboard cb = toolkit.getdefaulttoolkit().getsystemclipboard();          if (cb.isdataflavoravailable(dataflavor.javafilelistflavor))          {                try {                 string name = ""+cb.getdata(dataflavor.javafilelistflavor);              boolean found = false;                  if (name.tolowercase().endswith(".mp3]"))                      {                                 system.out.println("is mp3");                                 found = true;                              }                    if (!found)                {                         system.out.println("is not mp3");                    }                      }             catch(unsupportedflavorexception ex)              {                 ex.printstacktrace();                  }            catch(ioexception ex)              {                 ex.printstacktrace();                  }          }      } 

basically, yes. need check clipboard contents see if supports dataflavor.javafilelistflavor dataflavor. if does, need iterate on contents (which java.util.list of files) , make determination of content.

the following checks see if files .mp3 files (by checking name extension), wouldn't hard check isdirectory , recursive check of directory...

clipboard cb = toolkit.getdefaulttoolkit().getsystemclipboard(); if (cb.isdataflavoravailable(dataflavor.javafilelistflavor)) {     try {         list files = (list) cb.getdata(dataflavor.javafilelistflavor);         boolean found = false;         (object o : files) {             if (o instanceof file) {                 file f = (file) o;                 if (f.getname().tolowercase().endswith(".mp3")) {                     system.out.println("i haz mp3");                     found = true;                 }             }         }         if (!found) {             system.out.println("i notz haz mp3");         }     } catch (unsupportedflavorexception ex) {         ex.printstacktrace();     } catch (ioexception ex) {         ex.printstacktrace();     } } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -