1

I am trying to read/write files on Ubuntu 12.04. I set permission of that directory by chmod -R 777 . But still when I call canRead() method on that directory it returns false.

my directory is /root/Temp

please help me to solve this problem

Code (copied from comments):

File xyz = new File("/root/Temp"); 
System.out.println("filename :"+xyz.getPath()); 
System.out.println("can read :"+xyz.canRead()); 
String[] children = xyz.list(); 

Children is null, output of can read is false.

5
  • 5
    For better help sooner, post your code as an SSCCE that demonstrates your problem. This allows users to copy/paste and reproduce your issue. Include in your example the shell commands you used to create the directory. Commented Aug 13, 2013 at 9:52
  • run your program with sudo Eg. sudo java HelloWorld. Commented Aug 13, 2013 at 10:11
  • 1
    I've voted to re-open as we now have the code. Although it would be beneficial if you can still post the shell commands that construct your directory. Commented Aug 15, 2013 at 7:32
  • before specifying path give sudo..and try to pipe your password to the sudo command.. Commented Aug 15, 2013 at 8:01
  • I fired command with sudo but still its not giving permissions to read/write files using java Commented Aug 22, 2013 at 6:16

2 Answers 2

2

Are you running your program as root? it is not sufficient changing the permissions of /root/temp, if you are not the user root you wont be able to "go through" the dir /root unless you also change the permissions of the dir /root .

Sign up to request clarification or add additional context in comments.

6 Comments

I am root user. and creating folder using sudo.
Can you post your code as suggested by @DuncanJones ? that way we could help you better
code File xyz = new File("/root/Temp"); System.out.println("filename :"+xyz.getPath()); System.out.println("can read :"+xyz.canRead()); String[] children = xyz.list(); code children is null, output of can read is false.
@LaxmikantKumbhare What do you expect to read? Make sure Temp folder is not empty...
Works for me, using the code you posted as comment and running it as root. Your problem is elsewhere.
|
0

I too faced the same while doing XML Parsing using Java SAX Parser. My file is not read by the java program. The mistake I done was, I didn't specify the file name correctly. After your /root/Temp you have to add some more details too. For example : /root/Temp/example.xml Then your program will work fine. Hope this helps!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.