Results 1 to 1 of 1
- 02-10-2010, 01:01 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 5
- Rep Power
- 0
Using a character array with html
Hey guys,
I am working on this code that will (ultimately) read a line in the html code, and find the word "Title". That being the page title.
To do this, I think that I would need a character array.
Below is the code that I found on 'Rose India'. I have declared the character array, but I do not know where I mite fill it with the data.
Any help will be great.
Code:
import java.io.*;
import java.net.*;
public class SourceViewer{
public static void main (String[] args) throws IOException{
System.out.print("Enter url of local for viewing html source code: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String url = br.readLine();
try{
URL u = new URL(url);
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
int code = uc.getResponseCode();
String response = uc.getResponseMessage();
System.out.println("HTTP/1.x " + code + " " + response);
for(int j = 1; ; j++){
String header = uc.getHeaderField(j);
String key = uc.getHeaderFieldKey(j);
if(header == null || key == null)
break;
System.out.println(uc.getHeaderFieldKey(j) + ": " + header);
}
InputStream in = new BufferedInputStream(uc.getInputStream());
Reader r = new InputStreamReader(in);
int c;
while((c = r.read()) != -1){
System.out.print((char)c);
}
}
catch(MalformedURLException ex){
System.err.println(url + " is not a valid URL.");
}
catch(IOException ie){
System.out.println("Input/Output Error: " + ie.getMessage());
}
}
}
Thanks:)
(By the way, I develop websites and use a basic structure for each. With this code, I will be able to modify them with much greater ease.)
Similar Threads
-
Read from a certain character to a certain character
By blackstormattack in forum New To JavaReplies: 0Last Post: 03-16-2009, 11:36 AM -
Problem using the toUpperCase method with character array...
By lisalala in forum New To JavaReplies: 2Last Post: 02-24-2009, 04:32 PM -
comparing array using character
By Anseki in forum New To JavaReplies: 7Last Post: 10-03-2008, 07:28 PM -
reading text character by character
By bugger in forum New To JavaReplies: 2Last Post: 11-09-2007, 08:54 PM -
Problem with '/' character in HTML and JSP
By Marcus in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 07-04-2007, 05:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks