473,465 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading a File from another Web-Site.

dmjpro
2,476 Top Contributor
Hi, I tried this code ..... But I getting "ConnectException".
I am using a proxy.

Expand|Select|Wrap|Line Numbers
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class URLRead {
  5.  
  6.     /** Creates a new instance of URLRead */
  7.     public URLRead() {
  8.     }
  9.     public static void main(String args[]) throws Exception
  10.     {
  11.         //URL url = new URL("http://java.sun.com/j2se/1.4.2/docs/api/java/net/URL.html");
  12.         /*System.out.println("Protocol: " + url.getProtocol()+"\t"+
  13.                 "Host: " + url.getHost() + "\t" +
  14.                 "Port: " + url.getPort() + "\t" + 
  15.                 "Path: " + url.getPath() + "\t" +
  16.                 "File: " + url.getFile());*/
  17.         URL url = new URL("http","java.sun.com",8080,"/j2se/1.4.2/docs/api/java/net/URL.html");
  18.         InputStream in = url.openConnection().getInputStream();
  19.         FileOutputStream out = new FileOutputStream("c:/test.html");
  20.         int c;
  21.         while((c=in.read())!=-1) out.write(c);
  22.         in.close();
  23.         out.close();
  24.         System.out.println("Done...........");
  25.     }
  26. }
  27.  
Debasis Jana
Oct 11 '07 #1
4 3792
r035198x
13,262 MVP
Hi, I tried this code ..... But I getting "ConnectException".
I am using a proxy.

Expand|Select|Wrap|Line Numbers
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class URLRead {
  5.  
  6.     /** Creates a new instance of URLRead */
  7.     public URLRead() {
  8.     }
  9.     public static void main(String args[]) throws Exception
  10.     {
  11.         //URL url = new URL("http://java.sun.com/j2se/1.4.2/docs/api/java/net/URL.html");
  12.         /*System.out.println("Protocol: " + url.getProtocol()+"\t"+
  13.                 "Host: " + url.getHost() + "\t" +
  14.                 "Port: " + url.getPort() + "\t" + 
  15.                 "Path: " + url.getPath() + "\t" +
  16.                 "File: " + url.getFile());*/
  17.         URL url = new URL("http","java.sun.com",8080,"/j2se/1.4.2/docs/api/java/net/URL.html");
  18.         InputStream in = url.openConnection().getInputStream();
  19.         FileOutputStream out = new FileOutputStream("c:/test.html");
  20.         int c;
  21.         while((c=in.read())!=-1) out.write(c);
  22.         in.close();
  23.         out.close();
  24.         System.out.println("Done...........");
  25.     }
  26. }
  27.  
Debasis Jana
Was that the full exception that you got?
Oct 11 '07 #2
dmjpro
2,476 Top Contributor
Was that the full exception that you got?
Nah !
There is stack trace .............
Here is that ..........

Expand|Select|Wrap|Line Numbers
  1. Exception in thread "main" java.net.ConnectException: Connection refused: connect
  2.         at java.net.PlainSocketImpl.socketConnect(Native Method)
  3.         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
  4.         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
  5.         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
  6.         at java.net.Socket.connect(Socket.java:519)
  7.         at java.net.Socket.connect(Socket.java:469)
  8.         at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
  9.         at sun.net.www.http.HttpClient.openServer(HttpClient.java:382)
  10.         at sun.net.www.http.HttpClient.openServer(HttpClient.java:509)
  11.         at sun.net.www.http.HttpClient.<init>(HttpClient.java:231)
  12.         at sun.net.www.http.HttpClient.New(HttpClient.java:304)
  13.         at sun.net.www.http.HttpClient.New(HttpClient.java:316)
  14.         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:813)
  15.         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:765)
  16.         at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:690)
  17.         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:934)
  18.         at URLRead.main(URLRead.java:32)
  19. Java Result: 1
  20.  
  21.  
Debasis Jana
Oct 11 '07 #3
r035198x
13,262 MVP
Nah !
There is stack trace .............
Here is that ..........

Expand|Select|Wrap|Line Numbers
  1. Exception in thread "main" java.net.ConnectException: Connection refused: connect
  2.         at java.net.PlainSocketImpl.socketConnect(Native Method)
  3.         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
  4.         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
  5.         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
  6.         at java.net.Socket.connect(Socket.java:519)
  7.         at java.net.Socket.connect(Socket.java:469)
  8.         at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
  9.         at sun.net.www.http.HttpClient.openServer(HttpClient.java:382)
  10.         at sun.net.www.http.HttpClient.openServer(HttpClient.java:509)
  11.         at sun.net.www.http.HttpClient.<init>(HttpClient.java:231)
  12.         at sun.net.www.http.HttpClient.New(HttpClient.java:304)
  13.         at sun.net.www.http.HttpClient.New(HttpClient.java:316)
  14.         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:813)
  15.         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:765)
  16.         at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:690)
  17.         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:934)
  18.         at URLRead.main(URLRead.java:32)
  19. Java Result: 1
  20.  
  21.  
Debasis Jana
The port 8080 has to be open and accepting connections from you for you to be able to open it.
Oct 11 '07 #4
dmjpro
2,476 Top Contributor
The port 8080 has to be open and accepting connections from you for you to be able to open it.
Are you talking about [code=java]System.setProperty("http.proxyPort", "8080");[/coide].
I also set that before getting connection, but failed.

Debasis Jana.
Oct 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Erik Andersson | last post by:
Hi! I need to read a file (line-by-line) in reverse order, without reading the whole file into memory first. Is there an easy way of doing this? As in, is there a PHP function I could use? ...
4
by: Luca | last post by:
Hello Everybody, I'm a 26 years old Italian "Florentine" Computer technician :) I'm writing you about an idea that I've got of a function that could be introduced in new web browsers (or even...
5
by: Abyss | last post by:
My view. anyone that doesn't like it tough, click off and stop reading it. I have spent the last 45 minutes reading through all the posts, and I believe that you have all missed the mark of...
1
by: Michael Palmer | last post by:
I'm reading xml from SQL Server 2K with VB.net using an XSD schema file and SQLXML 3.0. I have the below code working fine, but I'd like to change the code from reading the schema file from a...
2
by: JS | last post by:
Hello all! I have come on to a problem for which I am not able to find a solution searching the web. What I am trying to do is reading a log-file with a size of 1.3 GB. When reading it using...
6
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
8
by: Martin Eyles | last post by:
Hi, I have a configuration file I made in xml which I am using to name a database server. (this way I can deploy my web page on various servers, and just change this file to make it work)....
14
by: Zahid | last post by:
Hi, What is a VDT file? How do I read a VDT file into my application? I know how to read text files etc but not VDT files. Im preparing in advance a prototype that read VDT files and does...
1
by: mtanq | last post by:
My project is an ASP-based web page, with C# as the language of choice. I have written a simple tree view that displays the structure of a file system mounted as 'MVFS' (On my system, it's W:/)....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.