Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: chmod



I'm wondering if "/あいうえお.txt" really is the name of the file.

Your original code works fine for me with a file of that name saved from TextEdit  - I copied the text from email and pasted to save-as box, and also into my IDE (Netbeans in this case).

How was the file created? From Terminal? Saved from another program?

Does something like:    new File("/あいうえお.txt").exists() return true? 

What if your program creates the file first, then tries to change its mode with exec of chmod?

btw, I'm using Java 1.5.0_13-b05-237 on OS X 10.5.1


On 30 Dec 2007, at 08:15, 中山 太雅 wrote:

Thank you for your reply.

It worked for me (with the escaped characters).  Are you sure
it's not because of the '/' at the beginning of your filename?
Is your file really in the '/' directory?
Yes, the file really exists on the path.

Does chmod work with this file when invoked from a Terminal window? Runtime.exec is a bit different, in that the input is not run through a shell (Terminal uses the bash shell by default). If it works from Terminal, try exec-ing a shell command, e.g.

   new String[] {
       "/bin/csh", "-c", "chmod g+w '/xxxxx.txt'"
   }
I tried the code but it didn't work too.

I finally found the code which works well:

public static boolean chmod (File path,String auth,boolean recursive)
{
boolean check = false;

Process process = null;
BufferedOutputStream bos = null;
try
{
process = Runtime.getRuntime ().exec (new String [] {"/bin/sh","-s"});

bos = new BufferedOutputStream (process.getOutputStream ());
bos.write (("chmod " + (recursive ? "-R " : "") + auth + " \"" + path.getCanonicalPath () + "\"\n").getBytes ("UTF-8"));
bos.flush ();
bos.close ();

process.waitFor ();
check = process.exitValue () == 0;
process.destroy ();
}
catch (InterruptedException ie)
{
check = false;
ie.printStackTrace ();
}
catch (IOException ioe)
{
check = false;
ioe.printStackTrace ();
}
finally
{
if (process != null) process.destroy ();
try {if (bos != null) bos.close ();} catch (IOException ioe) {ioe.printStackTrace ();}
}

return check;
}

Thank you.


=======================================================================
株式会社ベビーユニバース 開発部 中山 太雅

■PDF小説「5年後のベビーユニバース」下記よりダウンロード!
http://www.baby-universe.co.jp/company/dl.php?file=img/after5yearbu.pdf

・本社
〒251-0025 神奈川県藤沢市鵠沼石上1-13-13-304
Tel : 0466-55-3000  Fax : 0466-55-3001

・IV : イノベーションビレッジ
〒252-0816 神奈川県藤沢市遠藤4489番 212号室
Cel : 090-2422-1981(212号室内設置携帯)
=======================================================================

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: chmod (From: Kevin Ryan <email@hidden>)
 >Re: chmod (From: 中山 太雅 <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.