Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Checkin if a file exist within a directory

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Checkin if a file exist within a directory

    How do I check if a file typed in by the user in the FileDialog exist in the directory. if the file is not found or existed in teh directory a certain message is displayed. I do not know how to do that. Could I get some help.
    FileDialog fileWindow = new FileDialog(new Frame(),"Tash & David's File Founder System");
    fileWindow.setVisible(true);


    if (fileWindow.getFile() != null) {

    File fileDirectory = new File(fileWindow.getDirectory());

    String[] Directory = fileDirectory.list();

    for (; i < Directory.length; i++) {


    if(Directory[i].startsWith(fileWindow.getFile())){

    System.out.print("yes");


    }


    }


    }
    else
    JOptionPane.showConfirmDialog(null, "Are you Sure");
    }


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Checkin if a file exist within a directory

    1. Use code tags for enclosing the code in tags.
    2. Why don't you try File.exists()?

Similar Threads

  1. How to upload a pdf file to mysql from a directory?
    By A4Andy in forum JDBC & Databases
    Replies: 1
    Last Post: October 19th, 2011, 08:49 AM
  2. PROBLEM CHECKING IF RECORDS EXIST OR DO NOT EXIST IN DATABASE
    By jimmyb0206 in forum JDBC & Databases
    Replies: 1
    Last Post: April 10th, 2011, 09:18 AM
  3. Urgent - File exist nor working
    By Bagzli in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 2nd, 2011, 03:09 AM
  4. Help Remove file from pad directory
    By georgybaja in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 8th, 2011, 04:29 PM
  5. Virutal File Directory from Given dAta
    By hugsheals in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: July 28th, 2009, 03:39 AM

Tags for this Thread