Jfilechooser problem with getFile()

hi all
i have my application that, when a button is pressed, instantiates a fileChooser:
private void b_scegliActionPerformed(java.awt.event.ActionEvent evt)
        f_choos f=new f_choos();
        File fil=f.getFile();
        System.out.println("selected "+fil.getName());
}and my f_choos class with this methods;
public f_choos()
        initComponents();
        chooser.addChoosableFileFilter(new ImageFilter());
        chooser.setFileView(new ImageFileView());
        chooser.setAccessory(new ImagePreview(chooser));
        int result = chooser.showOpenDialog(null);
        if(result == chooser.APPROVE_OPTION)
            if(chooser.getSelectedFile()!=null)
                String name= chooser.getSelectedFile().getPath();
                getFile();           
    public File getFile()
        return chooser.getSelectedFile();
    }my problem is that, also when i press the "cancel " button, the file pointed by my fChooser is selected, but i want to be returned null
anyone could help me?
thanx in advance
sandro

Perhaps you could do something like this
public class f_choos {
    private File file;
    public f_choos() {
        initComponents();
        chooser.addChoosableFileFilter(new ImageFilter());
        chooser.setFileView(new ImageFileView());       
        chooser.setAccessory(new ImagePreview(chooser));               
        if(chooser.showOpenDialog(null) == chooser.APPROVE_OPTION) {           
                file = chooser.getSelectedFile();
    public File getFile()    {      
        return file; 
}

Similar Messages

  • Jfilechooser - problem with windows mapped dirs

    My Documents, Desktop and other windows mapped directories
    or network drives cause performance problems for the java file
    chooser class.
    I think because the file chooser has to resolve
    ambiguous paths for each file.
    i.e.
    1. Desktop\My Documents\myfile.doc
    2. c:\documents and settings\me\My Documents\myfile.doc
    3. Desktop\My Computer\c:\documents and settings\me\desktop
    4. Desktop\My Computer\c:\documents and settings\me\my
    documents\myfile.doc
    Most of our users are using xp and save most of their
    files to the My Documents directory.
    I need to find some work around. If this is not possible
    I could do with some tips on writing a directory service
    that will perform better on windows architecture.
    regards,
    Paul Cunningham

    It's still a serious problem. I am using WinXP with java 1.4.1_01. A folder on a mapped network drive with about 450 files in it takes an enormous amount of time to open & display. Once the file icons appear in the JFileChooser, scrolling and selecting in the JFileChooser is horrendously unresponsive.
    This problem (or related ones) seems to have been around for a long time. I wonder why it doesn't get fixed?
    - Dave P. -

  • JFileChooser problem with Windows Vista

    Hi,
    I running into the following problem.
    I am using JFileChooser in some of the JInternalFrames in my application. When I using Windows XP everthing works perfectly.
    Now Here is the issues, I have a new user using the application. His computer is Windows Vista and the error comes when I am using JFileChooser.
    I need to know I need to put another file or update ANYTHING ON WINDOWS VISTA FOR THIS JFileChooser to work.
    I appreacite your help and time.
    Wilfer
    CDC

    That's not an error from Java, as far as I know. Something else is producing it. Look over these search results for a case that matches what you see:
    http://www.google.com/search?q=error+31849

  • Anyone had problems with jFilechooser?

    I have problems with JFilechooser freezes when invoking returnVal = chooser.showDialog(this, "Select");
    For some reason it freezes the entire program, allthough sometimes (rarely), it doesn't freeze.
    Are there currently any problems with JFileChooser? I have not had any problems when embedding it in a window - only when using it on its own with JFileChooser chooser = new JFileChooser();
    Regards / Daniel

    There was a bug with JFileChooser where it would be unnecessarily slow when the directory it was showing contained huge zip files on Windows. It seems like it had something to do with the Win32 API calls they were making actually looked into all of the zip file's entries even though it didn't need to. This was fixed back in Java 6 update 10. What Java version are you using?
    If that isn't your problem, you'll have to post an SSCCE demonstrating your problem to get any help.

  • Problem with the JFileChooser

    Hello all,
    I'm having a small problem with the JFileChooser, the thing is whenever I click the cancel button in the dialog box a NullPointerException is thrown, so does anyone know wut is wrong?

    Either way, it's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of documentation that you can even download for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.
    Java� API Specifications
    Java� 1.5 JDK Javadocs
    Best of luck!
    ~

  • Problem with JFileChooser

    I have a problem with JFileChooser.showOpenDialogBox(Component c). When I select a directory and click the Open button,the program goes wacky. Same is the case if I click Cancel button without selecting any file. How to solve this problem. I want the directory be opened and all subdirectories and files be shown just as in MS Word for example.

    I have a problem with JFileChooser.showOpenDialogBox(Component c). When I select a directory and click the Open button,the program goes wacky. Same is the case if I click Cancel button without selecting any file. How to solve this problem. I want the directory be opened and all subdirectories and files be shown just as in MS Word for example.

  • Problem with Image file

    Hi,
    Iam facing with one problem.I have one swing interface through which I can upload files(back end servlet programme).Now I can upload all types of file but problem with image file it uploading perfectly that means size of the uploaded file is ok but its format damaged.It can not be open.My backend servlet programme is ok coz i tested it with html form it is working perfectly.Problem with swing interface.Plz guide me where I done a mistake.Below r my codes:-
    ImageIcon Upload=new ImageIcon("images/Upload.gif");
         Button=new JButton(Upload);
         Button.setToolTipText("Upload");
    Button.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
              int returnVal = fc.showOpenDialog(ActionDemo4.this);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = fc.getSelectedFile();
    String aa=file.getAbsolutePath();
              textArea3.append(aa);
                   textArea2.append("Local URL:");
    long l=file.length();
              try
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff);
              String str1=textArea10.getText();
    url = new URL ("http://127.0.0.1:7001/servletUpload?x="+str1);
         urlConn = url.openConnection();
         urlConn.setDoInput (true);
         urlConn.setDoOutput (true);
         urlConn.setUseCaches (false);
         urlConn.setRequestProperty("Content-Type","multipart/form-data;boundry=-----------------------------7d11e410e500f2");
         printout = new DataOutputStream (urlConn.getOutputStream ());
    String content ="-----------------------------7d11e410e500f2\r\n"+"Content-Disposition: form-data;"+"name=\"upload\"; filename=\""+aa+"\"\r\n"+"Content-Type: application/octet-strem\r\n\r\n\r\n"+conffile+"-----------------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);
    printout.flush ();
    printout.close ();
    Best Regards
    Bikash

    The errors are here:
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff); (conffile is a String object containing the image)
    and here:
    String content ="-----------------------------7d11e410e500f2\r\n"+"Con
    ent-Disposition: form-data;"+"name=\"upload\";
    filename=\""+aa+"\"\r\n"+"Content-Type:
    application/octet-strem\r\n\r\n\r\n"+conffile+"--------
    --------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);conffie is sent to the server but
    it's non possible to treat binary data as String!
    Image files must be sent as byte[] NOT as String ......

  • Problem with JFileChoosers

    I have a problem with JFileChooser.showOpenDialogBox(Component c). When I select a directory and click the Open button,the program goes wacky. Same is the case if I click Cancel button without selecting any file. How to solve this problem. I want the directory be opened and all subdirectories and files be shown just as in MS Word for example.

    Try and modify the following function:
         * Loads the FileChooser Object if not present.
         *@return Instance of File chooser
         private JFileChooser getFileChooser()
              if (mFlChooser == null)
                   mFlChooser = new JFileChooser();
                   mFlChooser.setFileFilter(
                        new javax.swing.filechooser.FileFilter()
                             public String getDescription()
                                  return sRes.getString("Text Documents (*.txt)");
                             * See Parent for Doc
                             *@param f See Parent for Doc
                             *@return See Parent for Doc
                             public boolean accept(File f)
                                  // Adapted
                                  if (f.isDirectory())
                                       return true;
                                  String extension = null;
                                  String s = f.getName();
                                  int i = s.lastIndexOf('.');
                                  if (i > 0 && i < s.length() - 1)
                                       extension = s.substring(i + 1).toLowerCase();
                                  if (extension != null)
                                       return extension.equals(".");
                                  return false;
              return mFlChooser;
         }

  • Problems with wlserver ant task for WL 8.1

    hi
    i have a problem with using wlserver ant task for Weblogic 8.1
    basically i want to start the server that is already preconfigured and deploy
    one ear.
    here's what i do:
    <taskdef name="wlserver" classname="weblogic.ant.taskdefs.management.WLServer">
    <classpath refid="lib.classpath"/>
    </taskdef>
    <wlserver action="start" dir="D:/BEA/user_projects/domains/mydomain"
    output="wls81.log"/>
    (and then the deployment task - irrelevant here)     
    the classpath is generated automatically and includes all jars in the specific
    project directory:
         <path id="lib.classpath">
         <fileset dir="${proj.lib.dir}">
              <include name="**/*.jar"/>
         </fileset>
         </path>
    (weblogic.jar is there as well)
    the problem is when i run it, the following happens:
    - if i have action="start" (or no action attribute at all), i get the following
    exception:
    java.lang.NullPointerException
    at weblogic.Home.<init>(Home.java:29)
    at weblogic.Home.getInstance(Home.java:86)
    at weblogic.Home.getPath(Home.java:94)
    at weblogic.Home.getFile(Home.java:99)
    at weblogic.ant.taskdefs.management.WLServer.execute(WLServer.java:260)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
    at org.apache.tools.ant.Task.perform(Task.java:341)
    at org.apache.tools.ant.Target.execute(Target.java:309)
    at org.apache.tools.ant.Target.performTasks(Target.java:336)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
    at org.apache.tools.ant.Main.runBuild(Main.java:609)
    at org.apache.tools.ant.Main.start(Main.java:196)
    at org.apache.tools.ant.Main.main(Main.java:235)
    - if i change it to action="startup" as specified on "wlserver Ant Task Reference"
    it seems that this task is skipped completely. no error messages, no stack trace,
    nothing. i tried -verbose and -debug options on ant, but there're no logs displayed
    whatsoever. it takes less than a second to run this task so i presume it's just
    getting skipped completely.
    i run this from the standalone Ant 1.5.4 on Windows environment.
    i've followed the topic "wlserver Ant task for WebLogic 8.1" where kind of similar
    problem is described but putting weblogic.jar on the system CLASSPATH is not an
    option for this project.
    anyone has any idea about how to get this going?
    cheers
    Andrei

    sounds bug to me. NPE should be correctly handled with appropriate error
    message. Please contact BEA support to log the call.
    "Andrei Rusakou" <[email protected]> wrote in message
    news:[email protected]...
    >
    hi
    i have a problem with using wlserver ant task for Weblogic 8.1
    basically i want to start the server that is already preconfigured anddeploy
    one ear.
    here's what i do:
    <taskdef name="wlserver"classname="weblogic.ant.taskdefs.management.WLServer">
    <classpath refid="lib.classpath"/>
    </taskdef>
    <wlserver action="start" dir="D:/BEA/user_projects/domains/mydomain"
    output="wls81.log"/>
    (and then the deployment task - irrelevant here)
    the classpath is generated automatically and includes all jars in thespecific
    project directory:
    <path id="lib.classpath">
    <fileset dir="${proj.lib.dir}">
    <include name="**/*.jar"/>
    </fileset>
    </path>
    (weblogic.jar is there as well)
    the problem is when i run it, the following happens:
    - if i have action="start" (or no action attribute at all), i get thefollowing
    exception:
    java.lang.NullPointerException
    at weblogic.Home.<init>(Home.java:29)
    at weblogic.Home.getInstance(Home.java:86)
    at weblogic.Home.getPath(Home.java:94)
    at weblogic.Home.getFile(Home.java:99)
    atweblogic.ant.taskdefs.management.WLServer.execute(WLServer.java:260)
    atorg.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
    at org.apache.tools.ant.Task.perform(Task.java:341)
    at org.apache.tools.ant.Target.execute(Target.java:309)
    at org.apache.tools.ant.Target.performTasks(Target.java:336)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
    at org.apache.tools.ant.Main.runBuild(Main.java:609)
    at org.apache.tools.ant.Main.start(Main.java:196)
    at org.apache.tools.ant.Main.main(Main.java:235)
    - if i change it to action="startup" as specified on "wlserver Ant TaskReference"
    it seems that this task is skipped completely. no error messages, no stacktrace,
    nothing. i tried -verbose and -debug options on ant, but there're no logsdisplayed
    whatsoever. it takes less than a second to run this task so i presume it'sjust
    getting skipped completely.
    i run this from the standalone Ant 1.5.4 on Windows environment.
    i've followed the topic "wlserver Ant task for WebLogic 8.1" where kind ofsimilar
    problem is described but putting weblogic.jar on the system CLASSPATH isnot an
    option for this project.
    anyone has any idea about how to get this going?
    cheers
    Andrei

  • JFilechooser Problem

    Hi,
    i have 2 problems with filechooser(jdk1.4.2)
    How can i deduct the change of Filetype in the Filechooser Combobox ,since
    i am entering some filename in the textfield of FC , if i change the File type the text inside the textfield is deleted .. i dont want to delete the text if i choose "all files " ..Can anyone suggest me how to do..?
    2.If i do some file/dir search for some letter ,the Scrolbar in List is not moving ,
    but the character is selected ..
    Regards
    Ganesan S

    You can add a PropertyChangeListener to JFileChooser and listen for JFileChooser.FILE_FILTER_CHANGED_PROPERTY events. The problem you describe is covered by the following bug report:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4678049

  • Problem with ImageIO.read()

    I have a problem with loading picture from file to variable Image img. Function ImageIO.read(fileIn) return always null pointer (whereas fileIn!=null). I'm using j2sdk-1_4_2_0. The same problem problem is in WindowsXP SP2 and Fedora 3 64bit.
    Here is code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    import java.awt.image.*;
    import javax.imageio.*;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import java.io.*;
    public class Converter extends JPanel implements ActionListener {
    JPanel mainPanel, info1Panel,info2Panel,convertionPanel, fSizePanel,displayPanel;
    JCheckBox enableConvertion;
    JButton selectFile,doIt,close;
    JRadioButton size1,size2;
    ButtonGroup sizeGroup;
    ImageIcon imagePrev;
    JRadioButton[] convertion = new JRadioButton[2];
    Image img;
    JLabel previewLabel;
    JFileChooser fc;
    File fileIn = new File("10.jpg");
    File fileOut;
    public Converter() {
    // Tworzenie paneli
    mainPanel=new JPanel();
    mainPanel.setLayout(null);
    info1Panel=new JPanel();
    info2Panel=new JPanel();
    convertionPanel=new JPanel(new BorderLayout());
    fSizePanel=new JPanel();
    displayPanel= new JPanel();
    //Tworzenie pozostalych elementow
    enableConvertion = new JCheckBox("Enable JPG <-> PNG");
    selectFile = new JButton("Select File");
    doIt = new JButton("Do it!");
    close= new JButton("Close");
    fc = new JFileChooser();
    size1 = new JRadioButton("The same resolution");
    size2= new JRadioButton("Resize image to target size of file");
    JLabel previewLabel = new JLabel();
    ButtonGroup sizeGroup = new ButtonGroup();
    imagePrev= new ImageIcon();
    // proba ulozenia elementow na ramce
    Insets insets = mainPanel.getInsets();
    Dimension size = selectFile.getPreferredSize();
    selectFile.setBounds(15 + insets.left, 15 + insets.top,size.width, size.height);
    doIt.setBounds(15 + insets.left,15+5+ insets.top+size.height,size.width, size.height);
    close.setBounds(15+insets.left,15+2*(5+size.height)+insets.top,size.width,size.height);
    convertionPanel.setBounds(10,150,250,90);
    convertionPanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Convertion"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    info1Panel.setBounds(150,10,200,140);
    info1Panel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Source File Information"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    info2Panel.setBounds(360,10,200,140);
    info2Panel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Target File Information"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    fSizePanel.setBounds(10, 250, 250, 90);
    fSizePanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("File size"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    fSizePanel.setLayout(new GridLayout(2,0));
    displayPanel.setBounds(270,150,290,190);
    displayPanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Display"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    previewLabel.setHorizontalAlignment(JLabel.CENTER);
    previewLabel.setVerticalAlignment(JLabel.CENTER);
    previewLabel.setVerticalTextPosition(JLabel.CENTER);
    previewLabel.setHorizontalTextPosition(JLabel.CENTER);
    previewLabel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createLoweredBevelBorder(),
    BorderFactory.createEmptyBorder(5,5,5,5)));
    previewLabel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createEmptyBorder(0,0,10,0),
    previewLabel.getBorder()));
    size1.setSelected(true);
    mainPanel.add(info1Panel);
    mainPanel.add(info2Panel);
    mainPanel.add(convertionPanel);
    mainPanel.add(fSizePanel);
    mainPanel.add(displayPanel);
    //osadzamy w odpowiednich panelach elementy
    mainPanel.add(selectFile);
    mainPanel.add(doIt);
    mainPanel.add(close);
    sizeGroup.add(size1);
    sizeGroup.add(size2);
    fSizePanel.add(size1);
    fSizePanel.add(size2);
    displayPanel.add(previewLabel);
    convertionPanel.add(enableConvertion);
    selectFile.addActionListener(this);
    public void actionPerformed(ActionEvent e) {
    int returnVal = fc.showOpenDialog(Converter.this);
    if (returnVal == JFileChooser.APPROVE_OPTION)
    File fileIn = fc.getSelectedFile();
    JFrame frame1=new JFrame();
    JOptionPane.showMessageDialog(frame1, fileIn.getName());
    if(fileIn==null)
    JFrame frame2 = new JFrame();
    JOptionPane.showMessageDialog(frame2,"FileIN==NULL");
    //############## PROBLEM IS HERE ###########################
    try
    Image img=ImageIO.read(fileIn); // HERE IS THE PROBLEM: img==NULL
    // WHERAS fileIn!=NULL
    }catch (IOException event){}
    if (img==null)
    JFrame frame2 = new JFrame();
    JOptionPane.showMessageDialog(frame2,"img==NULL");
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create a new instance of LunarPhases.
    Converter conv = new Converter();
    //Create and set up the window.
    JFrame convFrame = new JFrame("Conversion JPG <-> PNG");
    convFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    convFrame.setContentPane(conv.mainPanel);
    Insets insets = convFrame.getInsets();
    convFrame.setSize(600 + insets.left + insets.right,400+insets.top + insets.bottom);
    convFrame.setVisible(true);
    public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    //############## PROBLEM IS HERE ###########################
    try {
    Image img=ImageIO.read(fileIn); // HERE IS THE PROBLEM: img==NULL
    // WHERAS fileIn!=NULL
    } catch (IOException event){}
    if (img==null) {
        JFrame frame2 = new JFrame();
        JOptionPane.showMessageDialog(frame2,"img==NULL");
    }1. Please use [code] tags when posting code -- it makes the code more readable.
    2. When posting code, post a minimal example program. You could have filtered
    out all the extraneous GUI code, for example. Remember: the shorter the code, the
    more likely it is a forum member will read it! Posting long runs of code only
    hurts yourself.
    3. All that being said, your problem is a simple oversight: notice that the
    variable "img" in your try block is a local variable, not the field named "img"
    than you test after the try block.
    You should have written:
    try {
        img=ImageIO.read(fileIn);
    } catch (IOException event){
        e.printStackTrace();
    }

  • Resizng JFileChooser problem!!

    Hi,
    i have really wierd problem with JFileChooser.FileChooser is displayed very wide.It fills my screen.I use j2sdk1.4 and Windows XP.I used
    fileChooser.setPreferredSize(new Dimension(450,280));
    it is resized.But now ComboBox that allows me to choose where to save file is shown too long.Also buttons for "up one level","list","details" are not displayed.Please help me.
    greetings

    This is because there is a long string in the drop-down list at the top (possibly you have a meapped drive with a long path). For some reason (a bug?) JFileChooser seems to resize the dor-down list (and hence itself) to fit the longest path - at least on XP

  • JFileChooser problem - A bug ???

    Hi all,
    i am facing a unique problem with the JFileChooser. when i go to the "Look in" drop down list and select "Network Neighborhood", what i expect is to get a list of all computers on my LAN. i do get it, but the filechooser does seem to recognise the system names. the names that r displayed seem to be kind of substrings of "Network".
    E.g: etwork, ft Network, soft Network etc..., instead of proper system names.
    but when i double click on a folder, then it displays the shared folder names correctly, and also identifies the system name. it says something like:
    "folderName" on "systemName"
    if the filechooser is able to recognise the system name here, then why does it not display the system names properly in the aforesaid place (ie, when i select Network Neighborhood) initially.
    am running jdk ver 1.4, on a windows 98 system. is it somekind of a bug or am i missing something that i need to do ? could not find any help from the API.
    any idea anyone ???
    thanks
    - satyen

    1.4.2 has a fix for JFileChooser, although I am not
    sure its this problem, or hopefully the one I see
    often, when I click the drop down box to navigate to a
    network drive, it sometimes takes a VERY long time, on
    the order of hours, for the drop down to show up. On
    of our clients is seeing this now, so I am not sure
    why this is.The problem here is that Windows98 Network communication is appalling slow a lot of the time and some bits of it is broken.
    Getting the members list from a network can take an age simply because you sometimes have to broadcast a query on that network to find all the machines on it. This is not a Java related problem (although I suspect that VM support for Windows98 has slipped in priority ).

  • Resizing JFileChooser problem!!!

    Hi,
    i have really wierd problem with JFileChooser.FileChooser is displayed very wide.It fills my screen.I use j2sdk1.4 and Windows XP.I used
    fileChooser.setPreferredSize(new Dimension(450,280));
    it is resized.But now ComboBox that allows me to choose where to save file is shown too long.Also buttons for "up one level","list","details" are not displayed.Please help me.
    greetings

    Thanks
    I have updated Nvidia drivers, will try and reproduce problem.
    Hopefully I can't

  • Problem with retiriving links froma web page

    hi friends,
    ca n anyone help me out.i am trying to retrieve all the links from a web page .but all the linkjs are not being retrieved.can anyone tell me why.
    here i am submitting the code of it.
    private static ArrayList retrieveLinks(URL pageUrl, String pageContents, HashSet crawledList,boolean limitHost)
    // Compile link matching pattern.
    Pattern p = Pattern.compile("<a\\s+href\\s*=\\s*\"?(.*?)[\"|>]", Pattern.CASE_INSENSITIVE );
    Matcher m = p.matcher(pageContents);
    // Create list of link matches.
    ArrayList linkList = new ArrayList();
    while (m.find()) {
    String link = m.group(1).trim();
    // Skip empty links.
    if (link.length() < 1) {
    continue;
    // Skip links that are just page anchors.
    if (link.charAt(0) == '#') {
    continue;
    // Skip mailto links.
    if (link.indexOf("mailto:") != -1) {
    continue;
    // Skip JavaScript links.
    if (link.toLowerCase().indexOf("javascript") != -1) {
    continue;
    // Prefix absolute and relative URLs if necessary.
    if (link.indexOf("://") == -1) {
    // Handle absolute URLs.
    if (link.charAt(0) == '/') {
    link = "http://" + pageUrl.getHost() + link;
    // Handle relative URLs.
    } else {
    String file = pageUrl.getFile();
    if (file.indexOf('/') == -1) {
    link = "http://" + pageUrl.getHost() + "/" + link;
    } else {
    String path =
    file.substring(0, file.lastIndexOf('/') + 1);
    link = "http://" + pageUrl.getHost() + path + link;
    // Remove anchors from link.
    int index = link.indexOf('#');
    if (index != -1) {
    link = link.substring(0, index);
    // Remove leading "www" from URL's host if present.
    link = removeWwwFromUrl(link);
    // Verify link and skip if invalid.
    URL verifiedLink = verifyUrl(link);
    if (verifiedLink == null) {
    continue;
    /* If specified, limit links to those
    having the same host as the start URL. */
    if (limitHost && !pageUrl.getHost().toLowerCase().equals(verifiedLink.getHost().toLowerCase()))
    System.out.println("the given link does not exist");
    continue;
    // Skip link if it has already been crawled.
    if (crawledList.contains(link)) {
    continue;
    // Add link to list.
    linkList.add(link);
    return (linkList);
    Hope some one can help me outr of this .i susupect some problem with the regular expression used.
    it is unable to parse links like
    http://www.cricinfo.com/ci/engine/current/match/scores/live.html
    http://www.cricinfo.com/nzvind2009/content/current/series/366616.html

    kathiksagar wrote:
    i dont have much idea about html parser
    can u tell me how to do itHere are a couple of free parser written in Java:
    [http://java-source.net/open-source/html-parsers]
    I'm sure many of them have a manual, and/or have example code on their website on how to use it.
    Good luck.

Maybe you are looking for

  • Creating a Directory using a MacBook Pro

    I am trying to create a directory with photos next to the contact information that can be saved as a pdf so that people can have it in iBooks on their phone.  What is the best program to do this?

  • Performance issue entering monitor etc

    Dear Sirs, Our system currently feels quite slow. When entering the monitor for a load, or managing a cube the system it takes a while. In SM50 I can see it reads at table  (sequential) på RSMONIPTAB (which contains 1 millions records). SAP help.sap.

  • Mandatory condition mwst is missing ?

    hiiii experts i m practicing on ideas 1000, and i have using 1000 as a standard data. mwst is 0 in xd01 mwst is 0 in mm01 mwst is not mandatory in v/08 price for material has been updated in vk11 also. but still an error is coming of mwst mandtory co

  • OLAP Virtual cubes in PS 2010: what are their components ?

    Hi, I read somewhere that the 3 following OLAP Cubes in Project Server 2010 are virtual cubes built with the "aggregation" of several other cubes. What are these "primary" cubes? Thanks MSP_Portfolio_Analyzer MSP_Project_SharePoint MSP_Project_Timesh

  • Can boot in windows but not imac

    I can start my imac by pressing down the option button on startup, but I can only get on windows partition.  When I try to start up in mac, I get the grey screen with the apple logo.  I have tried everything.  Is there a way to fix the problem with t