Results 1 to 2 of 2

Thread: File handling

  1. #1
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

    Default File handling

    package first;

    import java.io.File;

    public class Mgr66
    {
    public static void main(String[] args)
    {
    File file = new File("e:/a/b/c");
    System.out.println(file.isAbsolute());
    System.out.println(file.getAbsolutePath());
    File file2 = new File("e://x//y//z");
    System.out.println(file2.isAbsolute());
    System.out.println(file2.getAbsolutePath());
    }
    }
    when i run the above program i got the below output
    true
    e:\a\b\c
    true
    e:\x\y\z


    but when i opened the path e:\ i did not get the floders a,b,c,x,y,z...............
    is there any specific reason.?

    Thanks & Regards
    Daya

  2. #2
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    101
    Rep Power
    0

    Default

    You need to call file.getParentFile().mkdirs(); to create the directories if they don't exist. You can also use FileWriter to actually write something to the file. Here's an example:
    Java Code:
    file.getParentFile().mkdirs();
    try {
        FileWriter writer = new FileWriter(file);
        writer.append('a');  //add a character to the file
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

Similar Threads

  1. File handling
    By Dayanand in forum New To Java
    Replies: 3
    Last Post: 03-22-2011, 04:20 PM
  2. File handling
    By Claude2005 in forum New To Java
    Replies: 17
    Last Post: 09-21-2010, 11:49 AM
  3. Regarding File Handling
    By ravjot28 in forum New To Java
    Replies: 1
    Last Post: 01-20-2010, 09:15 PM
  4. file handling problem
    By gcampton in forum Eclipse
    Replies: 19
    Last Post: 01-05-2010, 01:18 PM
  5. handling WAV file
    By zellazode in forum New To Java
    Replies: 1
    Last Post: 09-08-2009, 03:46 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
  •