• 0

File permissions in Unix


Question

4 answers to this question

Recommended Posts

  • 0

So after looking more into this, it seems I could do it by checking if in Unix with the path separator used, then if in Unix, I could execute a Unix command to get the file permissions string, but how do I execute a Unix command in Java and pull the result into a String object?

  • 0

I'm not sure exactly how much research you did into this, but it doesn't sound like you have the right solution for platform detection or the right idea for permission checking. You can find excellent Java API documentation online. It is always best to use functions in the standard library rather than using Runtime.getRuntime().exec() to launch a native executable, which I suspect is what you are attempting for permissions checking.

Without actually seeing your code, I can say that your "solution" for patform detection sounds like an unreliable hack. Instead, you should probably be using System.getProperty("os.name") to check which OS your program was launched on. There is an excellent example of this technique available here.

Similarly, you should probably be using the file class built into the Java standard library for permissions checking. A descent example of something somewhat similar can be found here.

I hope I have put you on the right path. If you have further questions, more specifics, such as the code you are struggling with, would be appreciated.

  • 0

Thanks xorangekiller,

The problem for me with using the file class in Java is that it only gives you access to basic permissions with three methods, canRead canWrite and canExecute where as if i am in unix, I will need the full permissions string which as shown in your example, it shows how to set it but not retieve it, any ideas how I could retieve it into a String?

Thanks, Tim

  • 0

I'm not exactly sure how you want the permissions formatted "into a String", but you should be able to retrieve them using the Files.getPosixFilePermissions() function. If you need them in some special format as a String, it shouldn't be too difficult to write a wrapper function to do so.

This topic is now closed to further replies.
  • Posts

    • BS, I've yet to run into a typical pc user that uses it at all, let alone half the population.
    • Codec Tweak Tool 6.7.7 by Razvan Serea This tool is a Swiss army knife for managing codecs and codec settings. Codec Tweak Tool will scan for broken filters and remove them. If the tool detects something that is broken, it will then prompt you with the details and you will be given the option to remove the broken item. Generate a detailed log of all installed codecs and filters, enable/disable more than 250 popular codecs and filters (if they are installed), manage preferred source filters, and reset settings. With this tool you can do things like: Scan the registry to detect and remove broken references to codecs and filters. Enable/disable more than 200 popular codecs and filters (if they are installed). Manage preferred source filters (a.k.a. splitters). Detect broken codecs and DirectShow filters. Fix problems with the standard DirectShow filters of Windows. A fix for a specific sound problem. Generate a text file with detailed information about all installed codecs and DirectShow filters, along with other relevant system information. Reset settings to recommended values for many popular codecs and DirectShow filters. Configure audio output settings for several popular audio decoders. Several configuration options for a few DirectShow filters that don't have an easily accessible interface for those options. Easy access to the configuration interfaces of various codecs and DirectShow filters Backup the settings of several codecs and DirectShow filters. Replace your current settings with those from a previous backup. Manage DirectShow filters - Enable or disable DirectShow filters. Manage ACM/VFW codecs - Enable or disable ACM/VFW codecs. Enable or disable DirectX Media Objects. Configure your preferred DirectShow source filters (a.k.a. splitters) for several common file extensions. Enable or disable the generation of thumbnails for several common video file formats in Windows Explorer. Download: Codec Tweak Tool 6.7.7 | 1.5 MB (Freeware) View: Codec Tweak Tool Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • The site is pretty sparse on features / tech specs. Can I plug it into a PC/hone/Switch via USB-C and use it as an external display? If so, what's the virtual resolution of the screen, the refresh rate, PPI of the image etc? Is the text crisp enough to use for coding at say 12pt? Is it good enough for playing dark games, like say Path of Exile 2? How about fast games like car racing games? Just how do they expect anyone to order this thing without giving out all this info?
  • Recent Achievements

    • One Month Later
      Vincian earned a badge
      One Month Later
    • First Post
      Jocimo earned a badge
      First Post
    • Week One Done
      suprememobiles48 earned a badge
      Week One Done
    • One Month Later
      Windows Guy earned a badge
      One Month Later
    • One Month Later
      Prasann earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      547
    2. 2
      +Edouard
      163
    3. 3
      PsYcHoKiLLa
      86
    4. 4
      neufuse
      65
    5. 5
      Steven P.
      65
  • Tell a friend

    Love Neowin? Tell a friend!