Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Exclamation java.io.FileNotFoundException: ..\log\server.log (Access is denied.

    Hi friends,
    I am getting problem while run following line:

    f=new File(strFileExt);
    out =new PrintStream(new BufferedOutputStream(new FileOutputStream(f,true)),true);

    The error is as follows:
    java.io.FileNotFoundException: ..\log\server.log (Access is denied.

    )

    at java.io.FileOutputStream.openAppend(Native Method)

    at java.io.FileOutputStream.<init>(FileOutputStream.j ava:177)

    at Test.ReadAndPrintXMLFile.main(ReadAndPrintXMLFile. java:86)


    Please check out the problem

    Thanks

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Is the file Read only? Or does some other app have a lock on it?
    What OS?

  3. #3
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Is the file Read only? Or does some other app have a lock on it?
    What OS?
    hi Norm,
    I have checked what u mentiond all ok.
    file is not read only
    there is no locking
    Os windows-2000

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In your BufferedOutputStream the second argument is set to true. Why is that? It should be the buffer size you going to use, so it's an int type.

  5. #5
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Default

    Dear Eranga,
    I think you didn't check carefully,the second true for PrintStream to on utoflush

  6. #6
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    you might not have the permission to write/create a file.
    i am the future

  7. #7
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Default

    Hi rjual,
    I already checked by already created file to specified path and also have the permission to write to that.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Is the path correct? What is the value of strFileExt?
    What is your current directory relative to the path?

  9. #9
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Default

    Dear Norm,
    I tried that by using by hardcoded path.
    that doesn't work giving same error
    Parimal
    java heart

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
    From the API doc.
    What happens if you remove the append flag?
    Or change the path/filename?

  11. #11
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Default

    I tried all possible way like changing path or filename.
    I think append flag is not matter of this problem
    Parimal
    java heart

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Have you tried it on other systems? Is there something about your environment that causes the problem?
    Can you strip the code to a minimum (like 20 lines) and post it here for others to try?

  13. #13
    jack239 is offline Member
    Join Date
    Jul 2008
    Posts
    35
    Rep Power
    0

    Default

    Hi,

    Use the file path as this: "c:\\temp\\myfolder\\abcd.txt"
    We were having problem in one windows mahine in accessing file path when we used "c:\temp\myfolder\abcd.txt". Adding one extra slash after each solved the problems.
    New to Java/PHP/Javascript development?
    For free help go to- www.techcubetalk.com

  14. #14
    jack239 is offline Member
    Join Date
    Jul 2008
    Posts
    35
    Rep Power
    0

    Default

    Also in UNIX you should use file patha as-
    "var/www/myfolder/abcd.txt' and know what Unix is very case sensitive.
    New to Java/PHP/Javascript development?
    For free help go to- www.techcubetalk.com

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by jack239 View Post
    Hi,

    Use the file path as this: "c:\\temp\\myfolder\\abcd.txt"
    We were having problem in one windows mahine in accessing file path when we used "c:\temp\myfolder\abcd.txt". Adding one extra slash after each solved the problems.
    Here we get an exception, use of a single slash(back slash). Because once JVM find a back slash it looking for a escape sequence. But there may not found a valid escape sequence with a single slash. To add a single slash you have to use two back slashes as follows.

    Java Code:
    c:\\temp\\myfolder\\abcd.txt
    In Java this is not a good practice at all. If you use this in a UNIX/Linux system it comes with a runtime exception. Because this pattern only valid in Windows systems. So the best way is the following in Java, since it's platform independent.

    Java Code:
    c:/temp/myfolder/abcd.txt

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  17. #17
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Default

    strFileExt="C:\\parimal\\log\\server.log";
    try
    {
    File f=new File(strFileExt);
    out =new PrintStream(new BufferedOutputStream(new FileOutputStream(f,true)),true);

    System.setOut(out);
    System.setErr(out);
    }catch(Exception e)
    {}

    But still giving like:
    java.io.FileNotFoundException: C:\parimal\log\server.log (Access is denied.

    )
    Parimal
    java heart

  18. #18
    mtv134 is offline Member
    Join Date
    Aug 2008
    Posts
    22
    Rep Power
    0

    Default

    which OS user runs the JVM?
    this user has to have the appropriate permissions on the file and the read permissions on the directory containing the file.
    visit http://www.thejavacode.com
    Muhammad Safwat

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    java.io.FileNotFoundException: C:\Temp\server.log (Access is denied)
    I get this when the output file is flagged as R/O

  20. #20
    parimal is offline Member
    Join Date
    Jul 2008
    Posts
    12
    Rep Power
    0

    Default

    Dear Norm,
    The problem got resolved.
    Actually while i am creating a file through the file i/o that creates a folder with extention .log which is read only
    Parimal
    java heart

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 05-22-2011, 03:16 PM
  2. java.io.FileNotFoundException
    By thevoice in forum New To Java
    Replies: 5
    Last Post: 06-13-2008, 08:38 AM
  3. SQL Server and MS Access
    By Hima in forum JDBC
    Replies: 0
    Last Post: 04-08-2008, 02:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •