0

I have a program that I want to publish that was built using Java. At the moment, the program creates folders / files in the directory:

"C:\Users\Steve\Documents\myProgram"

This obviously won't work unless the users have the exact same folder structure. How do I direct the program to a folder on the desktop? As the path "C:\Users\Steve\Desktop" wouldn't work.

Publishing the program using NetBeans creates a .jar. As I want the program to be used by many people, is it possible to create a batch file that using commands:

  • Creates a folder onto the desktop (that stores the program files created through the program)
  • Then launch the .jar

I could then get a converter and change the .bat to .exe. I'm not sure if this is the correct way about it.

On a side note, I'm pretty sure this wouldn't work as the user would still need Java installed to run the program. I'm not 100% sure, hence me asking.

Steven Mclaren
  • 275
  • 2
  • 6
  • 13
  • Test for directory existence and create it if it doesn't from your program. Java should be perfectly capable of this. – gbtimmon Dec 04 '12 at 21:29
  • @gbtimmon Thanks for the reply. If i was to create the directory in Java, how would I gather the PC's username. EG - If the directory was "C:\Users\Steve\Desktop" - How would I gather the username "Steve" – Steven Mclaren Dec 04 '12 at 21:31
  • http://stackoverflow.com/questions/585534/what-is-the-best-way-to-find-the-users-home-directory-in-java – gbtimmon Dec 04 '12 at 21:34
  • I understand that is not exactly what you asked for, but i think this i generally what you are really looking for.... – gbtimmon Dec 04 '12 at 21:36
  • possible duplicate of [What is the best installation tool for java?](http://stackoverflow.com/questions/173392/what-is-the-best-installation-tool-for-java) – Nik Reiman Dec 05 '12 at 12:38

1 Answers1

1

How do I direct the program to a folder on the desktop?

File desktopDir = new File(System.getProperty("user.home"), "Desktop");
File myFile = new File(desktopDir, "myFile.txt");
martinez314
  • 12,162
  • 5
  • 36
  • 63