File permissions in Java

Hi all,
I'm converting a python script to Java.
The script creates a directory with special file permissions, as seen below:
os.makedirs(options.file, 0777)
..Is there an equivalent way to set file permissions in Java (and would I need to bother what that..)?
/Best regards, H�kan Jacobsson - System developer in Sweden

Is there an equivalent way to set file permissions in JavaNot really. The File class allows you to set some permissions, but I don't think it lets you set the execute bit.
and would I need to bother what thatDepends entirely on why the original python programmer selected those options.

Similar Messages

  • Setting file permissions in java

    Hi,
    Iam uploading a file to a folder which exists on a unix machine.
    Iam using struts FormFile to upload a file.
    After uploading a file i observed that the permissions for the uploaded file are like this
    rw_ r-- r--
    for the owner it give read and write and for the rest only read permission.
    But i want read and write permissions for all the three.
    is there any way from java to change the permissions for a file on UNIX machine while uploading?
    I know RunTime.exec() . But they mentioned that it runs as a separate process instead of a thread.
    Can i use that? is there any problem by using RunTime..
    is there any other way to set permissions for file in java?

    You will have to use Runtime.exec(). Java doesn't allow you to set file permissions this specifically.
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Otherwise, you might want to look at this:
    http://www.jguru.com/faq/view.jsp?EID=19558

  • Changing file permissions in java

    Hi..
    I am creating log files using file handler class.They are created with some permissions in linux. Now I want to change the permissions of the those log files.
    I run this java code only once..so it should modify the permissions of the existing log files and the permissions of the new files getting created as well.
    Could u any one shed some light on it...
    Thanks in advance..

    Kiran,
    There are several ways to do this. I guess the easiest would be to change the "umask" of the (linux) user who is launching OC4J -- that way, any file created by that user will have the required permissions. Isn't that better than creating the files with the wrong permissions (in the first place) and them trying to change them afterward? (Or have I misunderstood your question?)
    Anyway, I fail to see how this is connected to OC4J?
    Good Luck,
    Avi.

  • Checking /Viewing Unix file permissions

    Is there a way for me to check file permissions (In Java) under unix, without having to call a system dependent function. (ie Runtime.getRuntime(); run.exec(....))
    Any help would be greatly appreicated.
    Curtney

    Thank you for replying.
    You are correct, I can detect ile permissions by using these functions, more specifically whether the current running application is able to read/write to a particular file.
    However, I am interest in knowing the file permissions /attributes
    for user and group on the unix file system despite whether the current running application can read/write to a particular file.
    ie,
    -rw-rw--r-- 1 username groupname size date .... filename
    I have searched and I believe, currently, there is not a class/member function that accomplishes the above.
    Again, Thanks for responding.
    Curtney

  • Permissions in Java

    I was reading up on file permissions in java at http://java.sun.com/developer/onlineTraining/Programming/JDCBook/appA.html
    I would like to know whether these permissions are for use only within Java or do they apply externally aswell.
    I mean if I dont allow write permission in my program and my program is currently running, then can the user still write to the file by opening it outside normally?
    Thanks.

    Note: This thread was originally posted in the [Java Media Framework|http://forums.sun.com/forum.jspa?forumID=28] forum, but moved to this forum for closer topic alignment.

  • Java File Permissions

    I'm relatively new to Java. I'm creating a program that will be running on 40 terminals, and will simulate a wireless mobile network. Our teacher has instructed that we should simply use a text file to keep track of where all the nodes are in the network, and when a node moves, it simply updates that text file. I'm looking to have some sort of system where the process checks to see if the text file has write permission, and if so, it will turn the permission to read-only, update the file, then set it back to write so nodes will be able to access the file and update locations while another node is updating, but another node will not be able to write to it until the node holding it has finished.
    I have looked in Class File, and I see checkWrite(), setReadOnly(), and checkRead(), but I'm not sure how to change the file permissions back to write.
    Am I going about this in the right way? If so, how do I change a file back to write access?
    Thanks, and if any more ingo is needed, let me know.

    java fully supports writable files. Look at class java.io.FilePermission. Your default java policy file may not allow you to write to files, but that can be edited manually or via the policytool . This forum should have several posts about how to modify the policy file so that you can write files. Once you edit that file, you will have read/write access, when appropriate.

  • File access Permissions in Java

    when the user select the file chooser button and browse through the directory in the local file system. If the user chooses any folder and that folder has readOnly access permission then the user can't copy the file into that folder as it has only Read access. So Please tell me how to give file and drive permissions in java on windows.

    File.setReadable() and friends, but "The operation will fail if the user does not have permission to change the access permissions of this abstract pathname." Check the return code.

  • Open file dialog in java apps causes segmentation fault

    Started to happen since sometime early in the java 1.5 releases (the early developer releases and still now)
    Programs like Eclipse (3.1.x) and Azureus (2.3.0.x), when I try and open a file using the toolbar or menu the application dumps. I am tried repairing permissions, deleting java config/cache files, etc. No luck.
    I thought I narrowed it down to either my external firewire drive or samba volume being mounted, but that seemed to just be a false positive.
    here is part of the backtrace:
    Local Time = Mon Jan 30 01:28:05 2006
    # This JavaNativeCrash log describes the Java state at a Native Crash in a Java application.
    # The corresponding native state can be found in the crash log generated by CrashReporter.
    # If this error is reproducible, please report it with the following information:
    # 1. Provide the steps to reproduce, a test case, and any relevant information
    # 2. This JavaNativeCrash_pid<num>.crash.log (Java state)
    # 3. The corresponding <name>.crash.log (native state; generated by CrashReporter)
    # File report at: http://bugreport.apple.com/
    # An unexpected Java error has been detected by HotSpot Virtual Machine:
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-57 mixed mode)
    # Bus Error (0xa) at pc=0xfffeff18, pid=10101, tid=25184768
    --------------- T H R E A D ---------------
    Current thread (0x005014f0): JavaThread "main" [thread_innative, id=-1610551960]
    Stack: [0xbf800000,0xc0000000)
    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j org.eclipse.swt.internal.carbon.OS.NavDialogRun(I)I+0
    j org.eclipse.swt.widgets.DirectoryDialog.open()Ljava/lang/String;+167
    dual core 2.3, 2.5gb ram, 2x36gb sata wd raptors   Mac OS X (10.4.4)  

    I forgot to tell you that we in this case use a remote connection through Cisco VPN. Are there difference in how Jinitiator and SUN's JPI handle this
    We also tried against other customer width the same result. It seems to have importance if you are remote or not. If you are on local LAN it seems to be the almost the same time if you use Jinitiator or SUN's JPI.
    //Robert

  • Problem with file permissions

    Hello all,
    I am making a simple HttpServlet, which takes input
    from html page and saves in to a file, but I'm having a
    bit of a problem with file permissions.
    I'm getting the following exception
    java.security.AccessControlException: access denied (java.io.FilePermission ./data/result read)
         java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
         java.security.AccessController.checkPermission(AccessController.java:427)
         java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         java.lang.SecurityManager.checkRead(SecurityManager.java:871)
         java.io.File.exists(File.java:700)
         SyksyHTTPServlet.doPost(SyksyHTTPServlet.java:31)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)The exception seems to occur when I'm trying to check whether the file already
    exists or not.
    The data directory has all permissions (read, write and execute) set for all users,
    and I have made an empty file called result inside the data directory for testing.
    This file has read and write permissions enabled for all users.
    Here's my code
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.Enumeration;
    import java.util.List;
    import java.util.ArrayList;
    public class SyksyHTTPServlet extends HttpServlet
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              int totalCount = 0;
              List list;
              String song = request.getParameter("song");
              PrintWriter out = response.getWriter();
              File file = new File("./data/result");
              if(file.exists())  // this is line 31, which seems to cause the exception
                   list = readFile(file);
              else
                   file.createNewFile();
                   list = new ArrayList();
              list.add(song);
              writeFile(file, list);
              for(int i = 0 ; i < list.size() ; i++)
                   out.println(list.get(i));
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              doPost(request, response);
         private List readFile(File file)
              List list = null;
              try
                   FileInputStream fis = new FileInputStream(file);
                   ObjectInputStream ois = new ObjectInputStream(fis);
                   list = (ArrayList)ois.readObject();
                   ois.close();
              catch(Exception e)
                   e.printStackTrace();
              return list;
         private void writeFile(File file, List list)
              try
                   FileOutputStream fos = new FileOutputStream(file);
                   ObjectOutputStream oos = new ObjectOutputStream(fos);
                   oos.writeObject(list);
                   oos.flush();
                   oos.close();
              catch(Exception e)
                   e.printStackTrace();
    }I'm using Tomcat 5.5 on Ubuntu Linux, if that has anything to do with this.
    I'll appreciate all help.
    kari-matti

    Hello again.
    I'm still having problems with this. I made
    a simple servlet that reads from and writes
    to text file. The reading part work fine on my
    computer, but the writing doesn't, not even
    an exception is thrown if the file exists that
    I'm trying to write to. If I try to create a new
    file I'll get an exception about file permissions.
    I also asked a friend of mine to try this same
    servlet on his windows computer and it works
    as it should.
    Here's the code
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class ReadServlet extends HttpServlet
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              String s = "";
              PrintWriter out = response.getWriter();
              String docroot = getServletContext().getRealPath( "/" );
              out.println("docroot: "+docroot);
              File file = new File(docroot+"test.txt");
              if(file.exists())
                   s = readFile(file);
                   out.println(s);
              else
                   out.println("file not found");
                   //file.createNewFile();                    // causes exception
                   //out.println("new file created.");
              writeFile(file, "written by servlet");
              out.println("Now look in the file "+file.getPath());
              out.println("and see if it contains text 'written by servlet'");
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              doPost(request, response);
         private String readFile(File file)
              FileInputStream fis = null;
              BufferedInputStream bis = null;
              DataInputStream dis = null;
              String s = "";
              try
                   fis = new FileInputStream(file);
                   bis = new BufferedInputStream(fis);
                   dis = new DataInputStream(bis);
                   s = dis.readLine();
                   fis.close();
                   bis.close();
                   dis.close();
              catch(Exception e)
                   e.printStackTrace();
              return s;
         private void writeFile(File file, String s)
              FileOutputStream fos = null;
              BufferedOutputStream bos = null;
              DataOutputStream dos = null;
              try
                   fos = new FileOutputStream(file);
                   bos = new BufferedOutputStream(fos);
                   dos = new DataOutputStream(bos);
                   dos.writeChars(s);
                   fos.flush();
                   bos.flush();
                   dos.flush();
                   fos.close();
                   bos.close();
                   dos.close();
              catch(Exception e)
                   e.printStackTrace();
    }And if someone wants to test this servlet I can
    give a war package.
    Any advices?
    kari-matti

  • File Permissions on Oracle Directories for other Operating System Users

    Hi,
    I am trying to export the table data to flat file using a pl/sql function using UTL_FILE package and directories created using 'CREATE DIRECTORY' command. The function is called from a stored procedure which in-turn is called from a Java program using JDBC and the Java process runs as different operating system user. The problem for me is the file exported is being written as 'ORACLE' user with 'OINSTALL' group and '-rw-r--r--' linux file permissions. When I try to read this exported file from the java program it throws me a file access error.
    I would like to know if we can specify any additional parameters either in
    1) Database parameter file
    2) UTIL_FILE.FOPEN function
    3) CREATE DIRECTORY command
    so that the files written to the DIRECTORY have a read write access.

    Since you attempting to read the file from Java, you are constrained by the OS.
    Write a stored proc to read the file, since PL/SQL does have the correct permissions to read/write to files.
    P;

  • File Permissions

    I am creating a file on solaris m/c using java.io.RandomAccessFile(filename,"rw"). My problem is that the file is created with the mode 664 (rw for owner, rw for group, r for other). I looked at the umask settings for the login running rmi and it is defined as 000 so ideally it should create the file with mode 666.
    Any hints about what could be be going wrong..

    ok, I created a shell script called showUmask
    #!/bin/sh
    umask > glop
    and created a test program :
    import java.io.*;
    public class R01 {
      public static void main(String [] args) {
        try {
        Runtime.getRuntime().exec("showUmask");
        RandomAccessFile raf = new RandomAccessFile("testfile.delme","rw");
        raf.write(72);
        raf.close();
        } catch (Exception e) {
    }I ran the program from a shell with different umask values set, and the file "testfile.delme" is created with the correct file permissions. Remembe to remove the test file before you run the program though, because if the file already exists, the permissions are not changed. Also, you cannot chnage the umask value by running umask from Runtime.exec(), you must ensure that the umask value is correctly set in the process that is spawing the JVM

  • Issues using XDOLoader - file permissions

    I have not yet run the XDOLoader utility successfully, but I'm trying to create an .ldt file to port our template .rtf files across database instances.
    Can anyone help me determine why I'm getting a file permissions error? (See below)
    I created a shell script with the following:
    # set Up CLASSPATH
    export CLASSPATH=$CLASSPATH:$HOME/java/DCRDpoi.jar:.:/opt/java1.3/lib/dt.jar:/opt/java1.3/lib/tools.jar
    # set up APPL_TOP var
    cd $APPL_TOP
    $AFJVAPRG oracle.apps.xdo.oa.util.XDOLoader DOWNLOAD \
    -DB_USERNAME user \
    -DB_PASSWORD pwd \
    -JDBC_CONNECTION server:port:SID \
    -LOB_TYPE TEMPLATE \
    -APPS_SHORT_NAME DCRD \
    -LCT_FILE /DEV1/code/applmgr/11.5.9/dev1appl/xdo/11.5.0/patch/115/import/xdotmpl.lct \
    -LDT_FILE testlob.ldt \
    -LOG_FILE testlob.log \
    This results in the following error relating to file permissions:
    XDOLoader started: Tue Mar 06 10:39:01 EST 2007
    Parameters passed to XDOLoader...
    [DOWNLOAD] [DOWNLOAD]
    [LDT_FILE] [testlob.ldt]
    [LCT_FILE] [DEV1/code/applmgr/11.5.9/dev1appl/xdo/11.5.0/patch/115/import/xdotmpl.lct]
    [LOB_TYPE] [TEMPLATE]
    [APPS_SHORT_NAME] [DCRD]
    [JDBC_CONNECTION] [oradev1.datacard.com:1529:DEV1]
    [DB_USERNAME] [user]
    [LOG_FILE] [testlob.log]
    [DB_PASSWORD] [pwd]
    Start downloading...
    Downloading files from XDO_LOBS: SELECT FILE_DATA, LOB_CODE, LOB_TYPE, APPLICATION_SHORT_NAME, FILE_NAME, LANGUAGE, TERRITORY, XDO_FILE_TYPE FROM XDO_LOBS WH
    ERE APPLICATION_SHORT_NAME = :APPS_SHORT_NAME AND LOB_TYPE in (:TEMPLATE, :TEMPLATE_SOURCE) AND LANGUAGE = :LANGUAGE AND TERRITORY = :TERRITORY
    Downloading files from XDO_LOBS: SELECT L.FILE_DATA FILE_DATA, B.TEMPLATE_CODE LOB_CODE, L.LOB_TYPE LOB_TYPE, L.FILE_NAME FILE_NAME, L.LANGUAGE LANGUAGE, L.T
    ERRITORY TERRITORY, L.XDO_FILE_TYPE XDO_FILE_TYPE, L.APPLICATION_SHORT_NAME APPLICATION_SHORT_NAME FROM XDO_TEMPLATES_B B, XDO_LOBS L WHERE B.APPLICATION_SHO
    RT_NAME = :APPS_SHORT_NAME AND B.TEMPLATE_CODE = L.LOB_CODE
    java.io.FileNotFoundException: Datacard Invoice_en_US.rtf (Permission denied (errno:13))
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at oracle.apps.xdo.oa.util.XDOLoader.saveDownloadFiles(XDOLoader.java:1617)
    at oracle.apps.xdo.oa.util.XDOLoader.processDownload(XDOLoader.java:1534)
    at oracle.apps.xdo.oa.util.XDOLoader.process(XDOLoader.java:927)
    at oracle.apps.xdo.oa.util.XDOLoader.main(XDOLoader.java:436)

    Please check permissions for directory from where you execute the command.
    By the way, XDOLOADER has nothing to do with ldt file. LDT file is for data definition and created/used by FNDLOAD. XDOLOADER is for moving template file itself.

  • File permissions: how do they work?

    Hi everybody,
    I've noticed a few posts on the forum here about file permissions, and it's made me quite curious. I'd really like to know how that works, and I have a few questions I hope somebody can answer.
    1. When you set a file's permission, say, canRead() is false, does that mean a human can't read it, the system can't read it, the JVM can't read it, or some combination of those options?
    2. Is it possible to set canRead() to false for a file contained in a jar so only the JVM can read it? (I guess that's kind of an offshoot of the first question)
    3. Are the canRead() and canWrite() functions some kind of lock on the file, like a password, and can they be overridden by a user?
    I think that's everything. If I think of anything else I'll probably post it, but for now if anyone can answer these 3 questions (or even one of them), I'd really appreciate it.
    Thanks!
    Jezzica85
    Message was edited by:
    jezzica85

    http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html
    Read the descriptions for canRead() and canWrite() for yourself. If I tell you you'll know what I said if you read it for yourself you'll know.
    PS.

  • File Permissions in windows XP

    ok im alittle stumped on this
    i need to give my application read\write access to %USERPROFILE%\\savedir
    now if i put it fully qualified
    i.e.
    permission java.io.FilePermission "C:\\Documents andSettings\\zaelld\\.saveDir", "read, write";
    it works fine
    by
    permission java.io.FilePermission "%USERPROFILE%\\.saveDir", "read, write";
    that should work as ide assume $HOME/.saveDir in linux would work fine(i havent tested that yet)
    and i ONLY want the program to have access to .saveDir
    any ideas? or have a missed something obvious:?

    well then i should have read the file permissions tutorial more carefully
    permission java.io.FilePermission "${user.home}\\.saveDir", "read, write";
    fixed

  • File permissions question

    I run Disk Warrior to repair file permissions every couple of days. The list of repairs is long enough that I have to scrol to get to the bottom. Today I decided to re run Disk Warrior, and it found 16 to repair the second time through, and 29 the thrid time through, 29 the fourth time through. What causes permission errors, and why does it take so many passes to correct them?
    ...JER

    This is an excerpt from DW's report. Notice it says what the permissions are, what they should be, and that the file was repaired. If what you say is true DW SHOULD SAY permissions are, permissions should be, don't worry about it, not repaired...
    Started verify/repair permissions on disk0s2 Macintosh HD!
    Permissions differ on "System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/dt.jar", should be
    lrwxr-xr-x , they are lrw-r--r-- !
    Repaired "System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/dt.jar"!
    Permissions differ on "System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar", should be
    lrwxr-xr-x , they are lrw-r--r-- !
    Repaired "System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar"!
    While your explanation may be correct, I'm still no closer to understanding.
    ...JER

Maybe you are looking for

  • How to merge multiple spools in one PDF

    hi all, i have a requirement to merge multiple spools into one PDF. I have the code to merge 2 spools into one PDF but acc to my requirement this number can be any( say 100). hence i need  help to merge N number of spools in one PDF. Regards geeta gu

  • Problem configuring vRealize Operations Manager

    Hi there, I have installed VRealize operations manager version 6.0 (trial version for 60 days) and ever since I have installed it, it says collecting data but not able to see any details of my vmware infrastructure in there. When I click on reports,

  • Voiding Complete Payment Run

    After a check run has been processed is there a way to void a complete check run. ie to void checks and reverse the clearing documents all at the same time. Al

  • Printing From iBook To Printer on Vista Desktop, Can't see shared printers

    Printing From iBook To Printer on Windows Vista Desktop, Can't see shared printer on a Vista machine from a Mac, although Windows notebooks find it immediately. I have previously always had success sharing printers on Windows XP machines with my iBoo

  • About tabular forms

    Hi I have created a tabular form with wizards. Now, there are check boxes on the left of each box. Now i want that the fields whose correspoonding check box is clicked should only be updated. But over here even if the record is not selected (i.e. che