Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Java - Find absolute path of file
  2. PathMatcher match = FileSystems.getDefault().getPathMatcher("glob:vjlc.{exe, jpg, png}");
  3.  
  4.         Path filename = FileSystems.getDefault().getPath("vjlc.exe","");
  5.  
  6.         if(match.matches(filename))
  7.         {
  8.             System.out.println(filename);
  9.         }
  10.        
  11. File fil = new File("vlc.exe");
  12.     System.out.println( fil.getAbsolutePath() );
  13.        
  14. String path = System.getenv("PATH");
  15. String pathSeparator = System.getProperty("path.separator");
  16.  
  17. for (String pathElement : path.split(pathSeparator)) {
  18.     File file = new File(pathElement, "vlc.exe");
  19.     if (file.isFile()) {
  20.         // vlc.exe exists in this location.
  21.     }
  22. }