Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

Connection Refused exception upon reading/parsing a shortcut file present in network drive

SAXBuilder builder = new SAXBuilder();
     try {
        File f = new File("\\\\bady\\SShare\\mart.xml");
        System.out.println(f.exists());   // Returns False
        System.out.println(f.length());   // Returns 0

        Document document = builder.build(f);  //IOException at this point
        Element root = document.getRootElement();
        Element paragraph = root.getChild("mart_element");
        String content = paragraph.getText();
        System.out.println("content = " + content);
        } catch (JDOMException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
Here mart.xml is a shortcut present in C:\Param\Bin on a windows box. I get the following IOException:

Exception in thread "main" java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.Socket.connect(Socket.java:524)
        at java.net.Socket.connect(Socket.java:474)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
        at sun.net.NetworkClient.openServer(NetworkClient.java:118)
        at sun.net.ftp.FtpClient.openServer(FtpClient.java:488)
        at sun.net.ftp.FtpClient.openServer(FtpClient.java:475)
        at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:270)
        at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:352)
        at JDOMElementTextContent.parseXml(JDOMElementTextContent.java:36)
        at JDOMElementTextContent.main(JDOMElementTextContent.java:47)
I tried to open Stream from URL using file: protocol but URLConnection.getInputStream throws the same connection refused exception.

Any recommendations would be appreciated?
0
gpmattoo8
Asked:
gpmattoo8
  • 5
  • 5
  • 4
  • +1
1 Solution
 
ksivananthCommented:
try C:\Param\Bin\mart.xml
0
 
CEHJCommented:
What does the following give at the command line?
dir \\bady\SShare\mart.xml

Open in new window

0
 
gpmattoo8Author Commented:
Volume in drive \\bady\SShare\ has no label.
 Volume Serial Number is 60DF-2818

 Directory of \\bady\SShare

File Not Found
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
CEHJCommented:
The file doesn't exist
0
 
gpmattoo8Author Commented:
Well, it does.
0
 
CEHJCommented:
Try mapping a network drive to, say, X:
0
 
gpmattoo8Author Commented:
Thanks for the suggestion!
However i would be running this program from a unix machine eventually.
0
 
ksivananthCommented:
you might want to pass the file location runtime through commandline arg or some config... so based on the platform you can give the location appropriately.
0
 
gpmattoo8Author Commented:
Sure i can! But thats not the solution to the underlying problem.
0
 
CEHJCommented:
You might also try a URL as the parameter to the SAXBuilder
0
 
gpmattoo8Author Commented:
I tried the URL but got the same exception.
0
 
CEHJCommented:
What do you get from the following at the command line?
explorer "\\bady\SShare"

Open in new window

0
 
ksivananthCommented:
it sounds like \\bady\SShare is an unix share... you can't use this in windows unless it is mapped to win throw something like citrix...
0
 
ksivananthCommented:
or you download the file to local win and then specify that in the parser
0
 
objectsCommented:
you can convert the file to a url, but if its not finding the file then its not going to find the url either

> However i would be running this program from a unix machine eventually.

You won't get this problem then. This problem is specific to Windows.
I'd suggest accessing the file on one of the local drives (as ksivananth suggested above) for testing, far less troublesome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now