Using the FilenameFilter interface to get the extension of a file

Hello...
I am trying to write a java program which is going to parse multiple xml documents and load them into the db. In a directory, there could be files other than xml files. Hence, i want to parse only files which have an .xml extension. I am using the FilenameFilter interface to get the extension of the files in a particular directory. However i am getting confused with the way it shd work...i am attaching herewith the code ...pl help me. I would appreciate if u could send me some sample code.
/* Author : Jayashree */
import com.xhive.XhiveDriverFactory;
import com.xhive.error.XhiveException;
import com.xhive.core.interfaces.XhiveTransactionIf;
import com.xhive.dom.interfaces.XhiveDocumentIf;
import com.xhive.core.interfaces.XhiveDatabaseIf;
import com.xhive.core.interfaces.XhiveConnectionIf;
import com.xhive.dom.interfaces.XhiveLibraryIf;
import org.w3c.dom.Document;
import java.io.*;
public class MultiXML
public static void main(String args[])
try
String administratorName = "Administrator";
String administratorPassword = "secret";
String DBName = "FirstDB";
XhiveConnectionIf fConnection = XhiveDriverFactory.getDriver().getConnection();
System.out.println("Got the connection");
fConnection.connect(administratorName,administratorPassword,DBName);
System.out.println("Connected");
XhiveTransactionIf fTrans = fConnection.createTransaction();
System.out.println("Transaction");
fTrans.begin();
System.out.println("Transaction begun");
XhiveDatabaseIf fDBase = fTrans.getDatabase();
String DBName1 = fDBase.getName();
System.out.println(DBName1);
XhiveLibraryIf rootLibrary = fDBase.getRoot();
System.out.println("Got the root");
File fDir = new File("e:/xhive");
File[] files = fDir.listFiles(new FileFilter("xml"));
int i = 0;
while ((i < files.length))
Document fDoc = null;
System.out.println("Document Initialized");
try
fDoc = rootLibrary.parseDocument(new File(files[i]+".xml").toURL(), XhiveLibraryIf.PARSER_NO_VALIDATION);
rootLibrary.appendChild(fDoc);
System.out.println("Appended");
catch (Exception e)
e.printStackTrace();
i++;
fTrans.commit();
System.out.println("Committed");
fTrans.terminate();
System.out.println("Terminated");
fConnection.close();
System.out.println("Connection Closed");
catch(Exception e)
System.out.println(e.getMessage());
In the above code, I am trying to list all those files which have the filter as .xml. I am unable to understand what code i need to write in the accept method of the FilenameFilter interface which accepts the directory name and the file name. There could be a directory which consists of multiple xml files too..this is where i am finding a problem
Regards,
Jayashree

This sample code uses an inner anonymous FilenameFilter that takes all readable files with a ".xml" extension.
File[] fileList = dir.listFiles (new FilenameFilter () {
    public boolean accept (File dir, String name) {
        if (!name.trim().endsWith (".xml"))
            return false;
        File f = new File (dir, name);
        if (!f.isFile())
            return false;
        if (!f.canRead())
            return false;
        return true;
});Please post any question if you don't understand.
Matthieu

Similar Messages

  • When I try to use an animation preset I get the following error...

    When I try to use an animation preset I get the following error...
    After Effects error: Cant import file "Evaporate.ffx": unsupported filetype or extension. (0::1)
    What do I do???

    As Rick says, you apply an animation preset, not import it.
    Since you're new to After Effects, I recommend starting here and working your way through the basic learning materials. Doing so will prevent much frustration.

  • When trying to verify the email address, I get the following message. Please help. This email address is already in use or you may already have an Apple ID associated with this email address. Please try again or sign in using your existing Apple ID.

    When trying to verify the email address, I get the following message. Please help. This email address is already in use or you may already have an Apple ID associated with this email address. Please try again or sign in using your existing Apple ID.

    Me too. I try to verify and i get the same message.
    I've created 3 alternate e-mail addresses and tried creating new accounts.
    Same Result!
    This is bullsh!t. How the **** can all 4 of my attempts result in the same freakin error???

  • I recieved an Adobe Master Collection License number from my school (Stevens Institute of Technology) and I can't figure out how to use it in order to get the product. I've created a username and that's as far as I've gotten.

    I recieved an Adobe Master Collection License number from my school (Stevens Institute of Technology) and I can't figure out how to use it in order to get the product. I've created a username and that's as far as I've gotten. I need to download the product and I can't figure out where to begin.

    Ask someone at your school... Do you have a Cloud redemption code, or a CS6 serial number?
    If Cloud, Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html and
    http://www.adobe.com/products/creativecloud/faq.html
    http://helpx.adobe.com/creative-cloud/help/install-apps.html to install or uninstall
    http://forums.adobe.com/community/download_install_setup/creative_cloud_faq
    What it is http://helpx.adobe.com/creative-cloud/help/creative-cloud-desktop.html
    Cloud Getting Started https://helpx.adobe.com/creative-cloud.html
    If CS6, download at Other downloads and enter your serial number when prompted
    Again... your 1st resource is your school

  • I have an iMac OS 10.9.5 - Every time I turn on my system I get the message that it can not access icloud and to fix it using iCloud preferences. I do not want to access or use iCloud, how do I get the message to discontinue?

    I have an iMac OS 10.9.5 - Every time I turn on my system I get the message that it can not access icloud and to fix it using iCloud preferences. I do not want to access or use iCloud, how do I get the message to discontinue?

    Hello mrmacjohn,
    Verifying that any iCloud account that may be signed in is signed out should resolve this error.
    On your Mac, open iCloud preferences, then click Sign Out.
    iCloud: Change iCloud feature settings
    http://support.apple.com/kb/PH2613
    Cheers,
    Allen

  • I updated the IPAD with the latest update and now when I turned the IPAD on, I get the itunes logo and then nothing else.  How can I fix this to let me use my IPAD?

    I updated the IPAD with the latest update and now when I turned the IPAD on, I get the itunes logo and then nothing else.  How can I fix this to let me use my IPAD?

    YOU ARE IN RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTunes (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port.
    DO NOT RELEASE BUTTON until you see picture of iTunes and plug
    5. Release Home button.
    ON COMPUTER
    6. iTunes has detected iPad in recovery mode. You must restore this iPad before it can be used with iTunes.
    7. Select "Restore iPad"...
    Note:
    1. Data will be lost if you do not have backup
    2. You must follow step 1 to step 4 VERY CLOSELY.
    3. Repeat the process if necessary.

  • HT2433 I purchased an external CD drive because the internal one died.  When I try using the new drive I get the following msg "The attempt to burn a disc failed.  The device is not accessable, probably because it was removed"

    I purchased an external CD drive for my MacBook,the internaldrive had died.  When I tried using the new drive I got the following msg "The attempt to burn a disc failed.  The device is not accessable, probably because it was removed"  I contacted OWC and tried to work the issue with them, we gave up and OWC sent me a replacement.  I connected the replacement and am getting the same message.  Any thoughts?

    Try resetting the SMC and PRAM first, if that doesn't help try a cleaning disc.....and then buy an inexpensive external burner. Slimline super drive failures are all too common.
    To reset the SMC
    Shut down the computer.
    Unplug the computer's power cord.
    Wait fifteen seconds.
    Attach the computer's power cord.
    Wait five seconds, then press the power button to turn on the computer.
    Resetting NVRAM / PRAM
    Shut down your Mac.
    Locate the following keys on the keyboard: Command (⌘), Option, P, and R. You will need to hold these keys down simultaneously in step 4.
    Turn on the computer.
    Press and hold the Command-Option-P-R keys before the gray screen appears.
    Hold the keys down until the computer restarts and you hear the startup sound for the second time.
    Release the keys.

  • My samsung says video out from i pad is not supported. i am connecting with apple dock using hdmi. I do get the audio

    my samsung says video out from i pad is not supported. i am connecting with apple dock using hdmi. I do get the audio  any suggestions?

    Jeffrey-
    If the HDMI input to the Samsung is not compatible, does it have a VGA or composite input?  I have both the HDMI and VGA adapters for the iPad, which work with the small Vizio HDTV I tried.  I understand a composite video adapter is also available.
    Fred

  • I'm running logic pro 8.0.2 on Leopard 10.5.8. I've recorded an evening of live music, the cut the recording into songs using one audio file folder. When working on an individual song, I can't access the sampler.  I get the message "nothing to display"

    I'm running logic pro 8.0.2 on Leopard 10.5.8. I've recorded an evening of live music, then cut the recording into songs using one audio file folder ad multiple song files. When working on an individual song, I can't access the sampler.  I get the message "nothing to display" or "no region or audio file selected"  After much research on the web, I believe this is a permanent bug.  Does anyone have a good work-around for this type of work.  We record live 16T band rehearsals constantly and would love to be able to break individual songs out of the large file and be able to use the sampler.  Thanks in advance for your ideas!  Cheers.

    Another thing - if I copy one of the tracks to another track, then the sample editor works on the copied track.  I don't want to have to copy 16 tracks to new tracks to be able to use the sample editor on a project.  Thanks again.

  • When trying to use my banking apps I get the error "Network Required  This application requires an active Internet Connection.  Please try again"

    When trying to use my banking apps I get the error "Network Required  This application requires an active Internet Connection.  Please try again".  This happens with two different apps from two different banks.  One of them works occasionally and have not figured out why.  I have cell signal and I am on a strong WiFi network.  Same thing happens when I turn off the WiFi too.    I have tried uninstalling and re-installing the app with no improvement.   I can't seem to find any setting that would cause this.   Does anyone have any suggestions?  

    I can access the internet just fine in the browser and i can use any other app i have.
    Sent from my Verizon Wireless 4G LTE DROID

  • After ejecting a disk plugged into the USB port using Finder, I am now getting "The disk was not properly ejected" message.  This didn't used to happen.  How can this be corrected?

    After ejecting a disk plugged into the USB port using Finder, I am now getting "The disk was not properly ejected" message.  This didn't used to happen.  How can this be corrected?

    When you right (control) click on the disk and click eject "disk name", do you pull it immeadiatly or wait a few seconds for it to unmount? Try waiting and see if you get the same message. If you do, when the disk is connected go to applications/utilities/disk utility, after opening DU, select the volume in question from the left side bar and try a permissions repair, you may also run verify disk and see if it comes up with any errors (they will be in red)

  • HT2731 I am using ipad2 with the latest version. While trying to make a apple Id, In the payment information  cannot get the option of "none" what will I do. Please help.

    I am using ipad2 with the latest version. While trying to make a apple Id, In the payment information  cannot get the option of "none" what will I do. Please help.

    You are following the instructions on this page for creating a new account : http://support.apple.com/kb/HT2534 e.g. selecting a free app in the store and tapping on 'create Apple id' when 'buying' the app ? I've just tried it and it works for me

  • I try to use the tools in photoshop elements 13, instead of one of the tools I only get the eraser. Whatt can I do?

    When I try to one of the tools in photoshop element 13 I get always the eraser. I push the brush. But I het once again the reaser.  What can I do to get one of the other tools? Joost van Santen

    Thank you very much. It helped. Joost van Santen
    Joost van Santen Light Art
    Kiefskamp 6  NL1082KA Amsterdam Netherlands
    T 00-31-20-6125404
    documentation <http://www.joostvansanten.nl>
    inspiration <http://www.lightart.nl>
    Op 12-11-14 21:06, Barbara B. <[email protected]> schreef:
    I try to use the tools in photoshop elements 13, instead of one of the tools
    I only get the eraser. Whatt can I do?
    created by Barbara B. <https://forums.adobe.com/people/Barbara+B.>  in
    Photoshop Elements - View the full discussion
    <https://forums.adobe.com/message/6923517#6923517>
    Go to the editor preferences>general, click this button and restart the
    editor: 
    https://forums.adobe.com/servlet/JiveServlet/downloadImage/2-6923517-694468/pr
    efs+reset.gif 
    <https://forums.adobe.com/servlet/JiveServlet/showImage/2-6923517-694468/prefs
    +reset.gif>
    Please note that the Adobe Forums do not accept email attachments. If you want
    to embed a screen image in your message please visit the thread in the forum
    to embed the image at https://forums.adobe.com/message/6923517#6923517 Replies
    to this message go to everyone subscribed to this thread, not directly to the
    person who posted the message. To post a reply, either reply to this email or
    visit the message page:  To
    unsubscribe from this thread, please visit the message page at
    . In the Actions box on the
    right, click the Stop Email Notifications link. Start a new discussion in
    Photoshop Elements by email
    <mailto:[email protected]ware.
    com>  or at Adobe Community
    <https://forums.adobe.com/choose-container.jspa?contentType=1&containerType=14
    &container=3347>  For more information about maintaining your forum email
    notifications please go to http://forums.adobe.com/thread/416458?tstart=0.
    >

  • Used CS6 for a year or more, now says it's not registered! I have 1 or 2 unused keys but do not want to use them. Can't get the CS6 applications to open to enter the codes I was given when I first registered them...

    Used CS6 for a year or more, now says it's not registered! I have 1 or 2 unused keys but do not want to use them. Can't get the CS6 applications to open to enter the codes I was given when I first registered them...

    You'll need to use web chat. This file shows you links to Web Chat:
    Adobe ID, sign in, and account help

  • When i try to use hulu acc.i keep getting the same message / sorry we are unable to load the player please check your internet connection clear your browser cache and try again. i thought i did it right .

    Question
    when i try to use hulu acc.i keep getting the same message / sorry we are unable to load the player please check your internet connection clear your browser cache and

    I found a solution! (at least, for my platform; Windows XP Home SP3, Firefox 4.0.1) =) Go to http://labs.adobe.com and download the Release Candidate 1 version of Adobe Flash 10.3.181.5. I swear, the Second I installed this, it worked INSTANTLY xD. Best of luck to you! (and anyone else who sees this =)
    -Erik P.

Maybe you are looking for