Jump to content

Recommended Posts

Posted

Other than Java's amazing OOP capabilities, it's main claim to fame is it's multi platform ability. Being able to run on Windows, Linux, OSX(Mac), and FreeBSD/OpenBSD is a great feature, but does have it's drawbacks. I found this in a recent project that I was developing in Java, but for running on only Windows Machines. I was trying to drop a file into the Windows APPDATA Directory, which is located in "D:\\Users\\Vorfin\\AppData\\Roaming\\" However due to the fact the drive letter, username, and even the whole path can change depending on the computer, and the operating system (XP, Vista, and Win.7. All have slightly different paths)

 

I found a lovely little Java function that allowed me to access the APPDATA folder, and in fact most(Probably All) Windows "Special Folders".

 

String APPDATA = System.getenv("APPDATA"); //Gets the directory of the APPDATA Folder.

Process pr = Runtime.getRuntime().exec(APPDATA + "\\File.exe"); //Runs an exe file from said directory.

Here is a list of the default Environment Variables for Windows XP,Vista, and Win.7.

 

(Remove the %%s)

 

Untitled.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...