1

Hi i want my java program to show a popup and gain read,write,delete file,folder permissions from user on the installed directory of my app i.e where my jar is located.how can i do that?

Harinder
  • 11,776
  • 16
  • 70
  • 126
  • You need to clarify your question. A Java program will run with the same permissions as the user has, unless it is an Applet in which case you need to sign it to gain rights to read and write files. Which platform is this? – Mathias Schwarz Jun 29 '11 at 10:39
  • @ Mathias Schwarz its a windows OS based app.so what should i do.should i check and tell the user that you donot have the required permissions on the installed folder? – Harinder Jun 29 '11 at 10:42
  • 2
    Yes, if the user does not have permission to write to a folder, then a Java program run by this user does not have this permission either. You should store user-specific data in the user's own folder. – Mathias Schwarz Jun 29 '11 at 10:49
  • @Mathias, I think there can be valid use cases where you want to check for specific permissions. For instance an app can be installed by an Admin and run by a _normal_ user, the app may need privileges on some directories... – Nivas Jun 29 '11 at 10:51
  • @Mathias so you r suggesting that i should store my data in user directory folder like documents or smting? – Harinder Jun 29 '11 at 10:53
  • @Nivas: Agree, but that is not how I understood the question. Maybe this answers the question? http://stackoverflow.com/questions/4662574/how-do-i-elevate-my-uac-permissions-from-java – Mathias Schwarz Jun 29 '11 at 10:55
  • 1
    @Dennis, You generally should be storing user data in the designated folders ("Application Data" on windows, "Application Support" on the mac, both under the user's home folder) rather than in, say C:\MyApp. – Nivas Jun 29 '11 at 11:01
  • @Mathias, yes it does. Perhaps you can post it as an answer and summarize it (or flag the question as duplicate) – Nivas Jun 29 '11 at 11:02
  • @Nivas so what path should i give to put data into these folder's and where are these folders in windows? – Harinder Jun 29 '11 at 11:03
  • @Nivas currently i am putting my data into a appData folder that i create from my program – Harinder Jun 29 '11 at 11:04
  • @Nivas i stored it in the Application Data folder of the user..Problem solved !! thnks – Harinder Jun 29 '11 at 11:28

2 Answers2

2

I think this previous question answers you question as well: How do I elevate my UAC permissions from Java?

The best way to go by it would be to avoid needing admin permissions for your application.

Community
  • 1
  • 1
Mathias Schwarz
  • 7,099
  • 23
  • 28
0

Stored the data into the user's temp folder

System.getProperty("java.io.tmpdir")
Harinder
  • 11,776
  • 16
  • 70
  • 126