• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Distribution - Special permissions required for read/write?

 
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,
I'm having some trouble with a program I'm writing here. I've compiled and packaged it using an installer. The jar works just fine on my computer (the one I've developed it on) after running the installer and using the shortcut and whatnot. But it seems to fizzle on any other computer. The program creates / modifies text files and I've tracked the program to the point where it attempts to create said files and it appears to hang there. Do I need to do anything special to get permissions to create/modify/delete these text files on other systems? If so - how do I do this?

Thanks!
 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried using the FilePermission class as well, requesting the read, write, execute and delete permissions for the directory where the jar is, but that didn't seem to have any impact, here's the code I used though:

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of looking for solutions, I would suggest that you should find out what the problem is first.

You have no idea whether your problem involves file permissions or not, that's just a guess. However it's quite likely that the code is throwing some kind of exception, so you should fix your application so you can find out what that exception is. Perhaps your code ignores exceptions? Perhaps it writes them to the console, but the way you deployed the application the console is invisible? Whatever the case, your first step should be to identify the problem.
 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Instead of looking for solutions, I would suggest that you should find out what the problem is first.

You have no idea whether your problem involves file permissions or not, that's just a guess. However it's quite likely that the code is throwing some kind of exception, so you should fix your application so you can find out what that exception is. Perhaps your code ignores exceptions? Perhaps it writes them to the console, but the way you deployed the application the console is invisible? Whatever the case, your first step should be to identify the problem.



I'm not sure how to go about doing that Paul - everything appears to be working just fine in the IDE, as well as compiled and installed on my PC. That's a good point about the console, I'll have to give that a shot, thanks!
 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay - I attached a simple console window to the program and tried it on a different computer and my suspicion appear to be correct:

java.io.IOException: Access is denied
java.io.IOException: Access is denied
Sep 02, 2012 6:07:23 PM splashScreen jButton1ActionPerformed
SEVERE: null
java.io.FileNotFoundException: classConfig.txt (The system cannot find the file specified)

Is the FilePermission class mentioned above not the correct way to handle this? Or did I use it in the wrong way?

 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just an update here (sorry for the multiple self bumps) but I did find a workaround for this problem. I ended up using this code:



I did this after reading a bit more about read/write permissions - a lot of other people had suggested just writing these types of files (used to store information that must be persistent, used in the program) to the users home folder, since everybody has read/write privs here and windows typically does not restrict read/write here.

Still curious though - is there a way to have these files read/written in the Program Files\<app name> directory?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Pettit wrote:Still curious though - is there a way to have these files read/written in the Program Files\<app name> directory?



No. Windows doesn't let you do that unless your program is running as an administrator. But why would you want to do that anyway? Didn't your installer already take care of setting up your program?

I was going to go on and say that if you're writing out files which belong to your application, you should write them to the user's home directory. But after re-reading your post less carelessly, I see that's exactly what you did. It's exactly what you should have done, too. Good work.
 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Joe Pettit wrote:Still curious though - is there a way to have these files read/written in the Program Files\<app name> directory?



No. Windows doesn't let you do that unless your program is running as an administrator. But why would you want to do that anyway? Didn't your installer already take care of setting up your program?

I was going to go on and say that if you're writing out files which belong to your application, you should write them to the user's home directory. But after re-reading your post less carelessly, I see that's exactly what you did. It's exactly what you should have done, too. Good work.



Awesome - thanks Paul! You're right about the installer, I hadn't considered that - I guess I was just trying to take the easy (lazy) route by trying to get the program to create the files in its own directory, despite this not being the preferred way of doing this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic