|
| |||||||||
| Tags: content, java, java script, jsp, programming language, web page |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Retrieve a web page content in java
Hello, I'm new here, I started in Java (well since the beginning of the year: d) and I try to create a class that makes it Fetches the number of results It gets the URL of the first (or nth but to implement) It connects to this URL It retrieves information selected Storage SQL Is it possible to specify the limits of my InputStream? Because when I try to compile the code, it gives me a error. I think I have a trouble to retrieve a web page content. If you have already done this then please help me. |
|
#2
| |||
| |||
| Re: Retrieve a web page content in java
Hello, Try changing the way of reading the page, that is you can try the following code: Code: StringBuffer src = new StringBuffer();
URLConnection url = u.openConnection();
url.setUseCaches(false);
url.connect();
Scanner sc = new Scanner(url.getInputStream());
/ / While there are still lines and we have not finished collecting data
while(sc.hasNextLine()){
src.append(sc.nextLine());
} |
|
#3
| |||
| |||
| Re: Retrieve a web page content in java
Hello, If you really want to read character by character, you can also do as before but with a buffer: Code: int b;
InputStream input = u.openStream();
StringBuffer s = new StringBuffer();
while ((b = input.read()) != -1){
s.append((char) b);
} / * while * /
/ / EOF reached
input.close(); |
|
#4
| |||
| |||
| Re: Retrieve a web page content in java
Hello, When you are trying to do this Code: while ((b = is.read()) != -1) s + =(char) b; / * while * / |
|
#5
| |||
| |||
| Re: Retrieve a web page content in java
Hello, Besides AC costs even more expensive since you also creates a StringBuilder for each iteration, as this code: Code: s + =(char) b; Code: s = new StringBuilder(s).append(b).function toString() {
[native code]
}(); |
|
#6
| |||
| |||
| Re: Retrieve a web page content in java
Hello, Indeed, the Scanner class (if you speak well of it) can play a stream more easily. But you can spend quite a StringBuffer is equally. When you get the int, you must know that this is int there and instead add it to the StringBuffer, he will just put it in another variable not? If you need more information on the same then you can visit the sun's official site and there you can find the documentation on this. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Retrieve a web page content in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unable to retrieve page in kindle based on page numbers | rUChIRr | Portable Devices | 6 | 08-07-2011 11:02 PM |
| Retrieve facebook fan page in PHP | Macario | Software Development | 5 | 28-11-2010 02:46 PM |
| Retrieve multiple values from java class | Ash maker | Software Development | 5 | 13-02-2010 12:05 AM |
| How to retrieve content advisor password? | Abhiraj | Windows Software | 3 | 08-08-2009 01:06 AM |
| How to retrieve XML data & display on the page in the table? | VijayW | Software Development | 2 | 16-02-2009 09:56 PM |