Java in MAC OS

Discussion in 'Mac Programming' started by chidambaram, Apr 17, 2009.

  1. chidambaram macrumors member

    Mar 9, 2008

    I am trying to create a application file in mac, using the below code.

    FileOutputStream fout;	
     fout = new FileOutputStream("/Users/laserwords/Desktop/");   		
      new PrintStream(fout).println ("tell application \"Finder\" \n set myFil to \"Macintosh HD:sample1.pdf\" as string	open file myFil \nend tell");		 
    catch (IOException e)	
    		System.err.println ("Unable to write to file");
    Above mentioned application file is created, But its type is, created as
    Application (Classic).

    So that file is, not executable.

    If we manually create, it is working properly.

    Can anyone help to resolve this?

    Thanks in advance.
  2. dr-jerry macrumors newbie

    Apr 15, 2009
    a stacktrace.

    How do you manually create it? I assume you need to set the umask to the file or even set some attributes to it.
    Ast this is mac specific java may not be the right choice to create those files, as the option should also be avaible on windows.

    plz ignore previous post as it was a matter of not reading the question..
  3. dr-jerry macrumors newbie

    Apr 15, 2009
    Giving it a second or rather third thought:
    grab a terminal, cd to the directory you're manuall creating the file in. And do a
    ls -l@
    (assuming you're doing leopard).
    You than need to figure out how to get java created file, have the same umask and attributes as the manually created file.
    You than should use java.lang.Runtime to modify this file.
    Hope this helps.
  4. chidambaram thread starter macrumors member

    Mar 9, 2008
    I open the script editor, Typed this

    tell application "Finder" 
     set myFil to "Macintosh HD:sample1.pdf" as string
    open file myFil end tell
    Saved this as,

    If i double click the file "", it will open ,sample1.pdf

    it is just like a bat file in Windows.
  5. wrldwzrd89 macrumors G5


    Jun 6, 2003
    Solon, OH
    The problem is that AppleScripts aren't plain text, but rather a cryptic binary format.
  6. chidambaram thread starter macrumors member

    Mar 9, 2008
    Thanks for your reply,

    is it possible to change plain text into cryptic binary format.

    So that it will be executable....
  7. mufflon macrumors 6502

    Sep 15, 2006
    the best alternative would be to download eclipse or netbeans, import the code and then export it as a runnable jar file with the main entry point to be the file you defined your "public static void main"... ... it'll be a .jar and not a .app, but it will do the trick and work just as well.
  8. chidambaram thread starter macrumors member

    Mar 9, 2008

    Thanks for ur reply.

    Actually my requirement to open a pdf file using java program. I installed netbeans in my Mac Machine.

    Without using this type of batch file ,can i open that file in any other way?
  9. kainjow Moderator emeritus


    Jun 15, 2000
    Use /usr/bin/open:
    open -a ~/Desktop/ /sample1.pdf

Share This Page