Member Panel


Sponsors and Ads

Live Tag Cloud

PC Forum PC Help Forum » Operating Systems » Other OS » [Answered] Java and Unix

Other OS - [Answered] Java and Unix posted in the Operating Systems forums; Ok folks... This is purely a programming question but most people who use unix probably know some java so i thought i`d give this place a shot. I'm in unix. ...

JOIN US NOW to remove these Ads

Post New Thread  Reply
  #1  
Old 03-01-2007
mintedjo's Avatar
Silver Member
My PC
 
Join Date: Sep 2006
Posts: 159
mintedjo - See this Members User comments on their Profile page
Question [Answered] Java and Unix

Ok folks... This is purely a programming question but most people who use unix probably know some java so i thought i`d give this place a shot.

I'm in unix.
I need to make a java program that gets the permissions of a specified file and displays them in octal notation.
eg.
  • "-rwxr-xr-x" would be represented as 755 in three-digit octal.
  • "-rw-rw-r--" would be represented as 664 in three-digit octal.
  • "-r-x------" would be represented as 500 in three-digit octal.
    (taken from wikipedia)
Thanks folks


__________________
teh 1337 j03
  #2  
Old 03-05-2007
ladygreenwitch's Avatar
Elite Member
 
Join Date: Jul 2005
Location: Bay Area California
Posts: 4,642
ladygreenwitch - See this Members User comments on their Profile page ladygreenwitch - See this Members User comments on their Profile page ladygreenwitch - See this Members User comments on their Profile page
Default

Hey Jo,

Welcome back. Sorry about the delay in getting to your post, I will PM Gar and Madmonkey about this, I beleive that they are our resident coders.

Keep an eye out for their posts.

TTFN

LGW


  #3  
Old 03-05-2007
madmonkey's Avatar
Site Manager
My PC
 
Join Date: Oct 2006
Location: South Wales
Posts: 5,538
PC Experience: PC Basket Ball Head!
madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page
Default

This might sound mad, but I have expereince in UNIX and experience in Java, but never worked with them togehter, so to be honest, I didn't realise they were not being displayed as octal in the first place.

You can get the permissions of a file using the getPermissions command.
Then it's just a matter of converting the string values to octal, by reading the first three digits in a string, and converting it, then the next three, and then the final three.

For example:
if (st = "---") {val = 0;}
if (st = "--x") {val = 1;}
if (st = "-w-") {val = 2;}
if (st = "-wx") {val = 3;}
if (st = "r--") {val = 4;}
if (st = "r-x") {val = 5;}
if (st = "rw-") {val = 6;}
if (st = "rwx") {val = 7;}

This isn't the full code, but I hope it gives you an idea of what you need to do.


__________________

Free Links: Hit Counter.. - ..Form Mail.. - ..Games.. - ..Amuz'd.. - ..Psychometrics Online.. - ..myFavorites Homepage
Submit your URL or Blog to: cyberJuice USA / UK online shopping links and blogs.
  #4  
Old 03-05-2007
mintedjo's Avatar
Silver Member
My PC
 
Join Date: Sep 2006
Posts: 159
mintedjo - See this Members User comments on their Profile page
Default

Thanks for that. If thats in documentation i must have missed it.


__________________
teh 1337 j03
  #5  
Old 03-05-2007
madmonkey's Avatar
Site Manager
My PC
 
Join Date: Oct 2006
Location: South Wales
Posts: 5,538
PC Experience: PC Basket Ball Head!
madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page madmonkey - See this Members User comments on their Profile page
Default

No problems, let me know if you need any further assistance.


__________________

Free Links: Hit Counter.. - ..Form Mail.. - ..Games.. - ..Amuz'd.. - ..Psychometrics Online.. - ..myFavorites Homepage
Submit your URL or Blog to: cyberJuice USA / UK online shopping links and blogs.
  #6  
Old 03-06-2007
mintedjo's Avatar
Silver Member
My PC
 
Join Date: Sep 2006
Posts: 159
mintedjo - See this Members User comments on their Profile page
Default

Hey. When i read this post i assumed it was a method from the File class. I appear to have been wrong. Can you explain in more detail please, firstly what class the getPermissions method is from and secondly how I would go about using it.
Thanks.


__________________
teh 1337 j03

Reply
New! Norton Internet Security 2008 – Download Now Click Here

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


All times are GMT +1. The time now is 04:56 AM.
Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC7
All Graphics & Content Copyright © 2004-2008 - PC Help Forum.com


Back to Top