Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Help in reading from a file:// url
Chetan Bengaluru
Greenhorn
Posts: 9
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class Tester { public static void main(String a[]) throws Exception{ URL url=new URL("file://host/D:/Chetan/sample.txt"); System.out.println("URL : "+url); FileInputStream fis=(FileInputStream)url.openStream(); int availSize=fis.available(); int count=0; while(count<availSize){ System.out.println(fis.read()); count++; } fis.close(); } }
I get a connection refused exception.
URL : file://hostname/D:/Chetan/sample.txt Exception in thread "main" java.net.ConnectException: Connection refused: connec t at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158) at java.net.Socket.connect(Socket.java:426) at java.net.Socket.connect(Socket.java:376) at sun.net.NetworkClient.doConnect(NetworkClient.java:139) at sun.net.NetworkClient.openServer(NetworkClient.java:118) at sun.net.ftp.FtpClient.openServer(FtpClient.java:423) at sun.net.ftp.FtpClient.<init>(FtpClient.java:687) at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.ja va:175) at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnec tion.java:257) at java.net.URL.openStream(URL.java:960) at tests.Tester.main(Tester.java:13)
Can some body tell me why so?
Vijay Vaddem
Ranch Hand
Posts: 243
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You need to open the connection first...
Try this...
try { URL url = new URL("file://host/D:/sample.txt"); URLConnection uc = url.openConnection() ; InputStream in = uc.getInputStream() ; byte[] buf = new byte[4096]; for(int br = in.read(buf); br > -1; br = in.read(buf)){ System.out.write(buf, 0 , br); } in.close(); }catch (Exception e){ e.printStackTrace(); }
Vijay
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Access to website using Java Code
java.net.ConnectException: Connection timed out:check service is available or not
SSH Port forwarding-FTP Access
Connection Refused exception upon reading/parsing a shortcut file present in network drive
Problem with FTPClient
More...