Results 1 to 6 of 6
  1. #1
    decode_urself is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default java file handling problem

    import java.util.*;
    import java.io.*;
    class Test
    {
    public static void main(String [] args)
    {
    File f2=new File("E:\\data.txt");
    long b=f2.length();
    System.out.println(b+f2.getName()+f2.getPath() +f2.getAbsolutePath()+f2.exists());
    boolean a=f2.isFile();
    System.out.println(a);
    }



    }

    the length() method returns 0 rather than the actual size . f2.exists() always returns false .. isFile() always returns false ..
    Plzzz reply asap

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

    Default Re: java file handling problem

    I guess the file doesn't exist?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,240
    Rep Power
    19

    Default Re: java file handling problem

    Quote Originally Posted by decode_urself View Post
    Plzzz reply asap
    Recommended reading: this and this

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    decode_urself is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: java file handling problem

    it exists .. the other methods .. return the correct name and path .. but exists() and length() are not working .

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: java file handling problem

    The paths will shows the correct path, but that does not mean the file exists.
    Java Code:
    File f = new File("someFIleThatDOesNotExist.txt");
    System.out.println(f.getAbsolutePath());
    That will print out a path.
    That path represents the path that will be used when the file is actually created.
    It does not currently exist.

    So, as Jos says, the File does not exist.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,240
    Rep Power
    19

    Default Re: java file handling problem

    Quote Originally Posted by decode_urself View Post
    it exists .. the other methods .. return the correct name and path .. but exists() and length() are not working .
    Stubborn, huh?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. File handling
    By Dayanand in forum New To Java
    Replies: 7
    Last Post: 03-23-2011, 07:31 AM
  2. Replies: 0
    Last Post: 12-22-2010, 11:32 PM
  3. Java/OS File Handling
    By Revenna in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 10:08 AM
  4. file handling problem
    By gcampton in forum Eclipse
    Replies: 19
    Last Post: 01-05-2010, 01:18 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
  •