3 Replies Latest reply on Apr 16, 2011 8:00 AM by Dude!

    Problem in creating log file on Ubuntu(Linux)


      I have developed a project in java. which creates log file for exception handling. This is working fine on Windows but When I run the jar file on ubuntu then it is not creating log file and throwing an error.

      Error Message="Permission Denied UnixFileSystem.java createFileExclusively()"

      Code is :
      strStartupPath = new java.io.File("").getAbsolutePath();
      DateFormat dateformat = new SimpleDateFormat("yyyyMMdd");
      Date date = new Date();
      String strFileName = strStartupPath + "\\" + dateformat.format(date) + ".log";
      File logFile = new File(strFileName);

      Your assistance will be appriciated.

        • 1. Re: Problem in creating log file on Ubuntu(Linux)
          It looks like you need to check directory permissions or the actual value of whatever the "strStartupPath" variable represents. If you know the directory, you can change permissions, e.g. chmod u+w,g+w mydir, which will give the owner and group write access.
          • 2. Re: Problem in creating log file on Ubuntu(Linux)
            This application needs to run on linux, MAC and Windows. The strStartupPath should be the path where the application is run. This application works fine on a windows or MAC. However we are getting this error while running the same on Ubuntu (we are using the same as a testing OS for Linux). However if I need to provide the solution as you have suggested, I have to first determine the OS and then run this command only for Linux. You will have to help me out with determining the OS as well.

            Thanks for you help.

            • 3. Re: Problem in creating log file on Ubuntu(Linux)
              If you want to do this properly then you will have to make it OS specific. Various security systems on each platform will prevent you from freely writing your logfile unless you choose the correct location. The applications folder under MacOSX, for instance, requires Admin privileges. Under MacOSX and Windows, log files are typically stored in the Applications Data resp. /Library/Logs or ~/Library/Logs folder in MacOS X. In Unix and Linux you will typically use /var/log directory.

              I think your question is rather Java than Linux specific, but there is a lot of information available for free on the web.

              Perhaps the following example can help you to determine the OS:
              public static final class OsUtils
                 private static String OS = null;
                 public static String getOsName()
                    if(OS == null) { OS = System.getProperty("os.name");
                 public static boolean isWindows()
                    return getOsName().startsWith("Windows");
                 public static boolean isUnix() // and so on
              Edited by: Dude on Apr 16, 2011 12:58 AM