Results 1 to 18 of 18

Thread: File handling

  1. #1
    Claude2005 is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default File handling

    Hello there,

    I'm using NetBeans 6.9.1 in Windows and I wanted to do a simple file handling. First, I wanted to check if a file exists. The file I wanted to open is in UNIX. I've tried the code below. It works if you're looking for a file that's in Windows. It doesn't work if you're looking for a file that's in UNIX.

    Java Code:
    String path = "<path here>";
    File f = new File(path);
    boolean ext = f.exists();
    Thanks in advance :D

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

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

  4. #4
    Claude2005 is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Can you show me the file path, how did you define it?
    /home/<username>/test.txt :D

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Yes, do you get any errors?
    Does the user the Java code is running under have permission to view the directory the file is in?

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

  7. #7
    Claude2005 is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    No, I didn't get any error message. And yes, the file exist in the UNIX directory. I already did the chmod 755 command.

    EDIT:

    Someone told me here that I have to move my server to a linux box. Will that help?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    You mean you're not running this on the same box?
    You could have mentioned that.
    Where is the code running (what OS)?

  9. #9
    Claude2005 is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    Let me clarify a bit,

    As of now, I'm using the Tomcat 6.0 that's built-in with NetBeans 6.9.1, which is installed on Windows XP SP3. What my friend told me is that I should have a different server that is running on a Linux box. I think the OS that's available here is Solaris 9 or 10.

    My concern now is that, will it help me in my situation by having a different server that's running in a Linux box?

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    So you have your code on a Windows box, and you are attempting to access a file on a Unix box?

    I just need to clarify what it is you are trying to do.

  11. #11
    Claude2005 is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    Yes, that is correct :D

    EDIT:

    Do you need to input somewhere the hostname, your UNIX username and password?

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    This is why.
    I asked earlier if the file was visible to the user the Java program was running as...

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Claude2005 View Post
    Yes, that is correct :D

    EDIT:

    Do you need to input somewhere the hostname, your UNIX username and password?
    Were you expecting miracles? I have a couple of laptops and my home directory is /home/jos on all my machines but you can't reach them (I can). Unless you have a Samba server running there is no file system involved so you should reach that file through other means. Authorization is more than likely required. You should've mentioned those 'details' when you started this topic.

    kind regards,

    Jos

  14. #14
    Claude2005 is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    Wow, talk about being kind with the new guys here...

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Well, it does get frustrating when you ask questions and they aren't answered sufficiently, only to find that a full answer would have helped significantly.

    We do have jobs you know...

  16. #16
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Claude2005 View Post
    Wow, talk about being kind with the new guys here...
    Kindness has nothing to do with it; if you want us to help you you have to supply all the (relevant) information. Vague indications are not enough and often misleading (as you could've noticed).

    kind regards,

    Jos

  17. #17
    Claude2005 is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Well, it does get frustrating when you ask questions and they aren't answered sufficiently, only to find that a full answer would have helped significantly.

    We do have jobs you know...
    Sorry about that. It's just me that's being new in this kind of field.

    Kindness has nothing to do with it; if you want us to help you you have to supply all the (relevant) information. Vague indications are not enough and often misleading (as you could've noticed).
    I'm giving vague information because I really don't know what to say. Sorry for being a newbie in this field.

  18. #18
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Claude2005 View Post
    I'm giving vague information because I really don't know what to say. Sorry for being a newbie in this field.
    It's OK, you're no exception to the rule; lots of people new to programming and computers panic and give just vague irrelevant indications and they want immediate help. We don't have crystal balls and the field of computer science has nothing to do with magic so only clear information counts, only then are we able to help you. At least describe your computing environment that's giving you trouble ...

    kind regards,

    Jos

Similar Threads

  1. Java/OS File Handling
    By Revenna in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 10:08 AM
  2. Regarding File Handling
    By ravjot28 in forum New To Java
    Replies: 1
    Last Post: 01-20-2010, 09:15 PM
  3. file handling problem
    By gcampton in forum Eclipse
    Replies: 19
    Last Post: 01-05-2010, 01:18 PM
  4. handling WAV file
    By zellazode in forum New To Java
    Replies: 1
    Last Post: 09-08-2009, 03:46 PM
  5. Problem in File Handling in Java
    By getbiplab in forum New To Java
    Replies: 6
    Last Post: 03-31-2008, 12:02 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
  •