Whats the wrong with this code?
Posted
by girinie
on Stack Overflow
See other posts from Stack Overflow
or by girinie
Published on 2010-03-13T18:55:53Z
Indexed on
2010/03/13
19:05 UTC
Read the original article
Hit count: 337
Hi in this code first I am downloading a web-page source code then I am storing the code in text file. Again I am reading that file and matching with the regex to search a specific string. There is no compiler error. Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/CharSequence Can anybody tell me Where I am wrong.
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WebDownload
{
public void getWebsite()
{
try{
URL url=new URL("www.gmail.com");// any URL can be given
URLConnection urlc=url.openConnection();
BufferedInputStream buffer=new BufferedInputStream(urlc.getInputStream());
StringBuffer builder=new StringBuffer();
int byteRead;
FileOutputStream fout;
StringBuffer contentBuf = new StringBuffer();
while((byteRead=buffer.read()) !=-1)
{
builder.append((char)byteRead);
fout = new FileOutputStream ("myfile3.txt");
new PrintStream(fout).println (builder.toString());
fout.close();
}
BufferedReader in = new BufferedReader(new FileReader("myfile3.txt"));
String buf = null;
while ((buf = in.readLine()) != null) {
contentBuf.append(buf);contentBuf.append("\n");
}
in.close();
Pattern p = Pattern.compile("<div class=\"summarycount\">([^<]*)</div>");
Matcher matcher = p.matcher(contentBuf);
if(matcher.find())
{
System.out.println(matcher.group(1));
}
else
System.out.println("could not find");
}
catch(MalformedURLException ex) {
ex.printStackTrace();
}
catch(IOException ex){
ex.printStackTrace();
}
}
public static void main(String [] args)
{
WebDownload web=new WebDownload();
web.getWebsite();
}
}
© Stack Overflow or respective owner