han
Hi friends,
I am trying to write the html documents into text ocuments from a directory, but getting the error of :
TextFromHtml.java:47: cannot resolve symbol
symbol : method parse (java.io.Reader,TextFromHtml,boolean)
location: class javax.swing.text.html.parser.ParserDelegator
new ParserDelegator().parse(r, parser, true);
my code is below.
import java.io.*;
import java.net.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;
publicclass TextFromHtml
{
//File directory=new File(".");
//String[] files=directory.list();
publicvoid handleText(char[] data,int pos)
{
File directory=new File(".");
String[] files=directory.list();
try
{
for(int i=0; i<files.length;i++)
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(files[i]+"txt")));
pw.println(data);
pw.close();
}
}
catch(IOException io){}
System.out.println(new String(data));
}
publicstaticvoid main(String[] args)
{
File directory=new File(".");
String[] files=directory.list();
try
{
for(int a=0;a<files.length;a++)
{
String filename=files[a];
Reader r=new FileReader(filename);
TextFromHtml parser=new TextFromHtml();
new ParserDelegator().parse(r, parser,true);
}
}
catch(IOException e)
{
e.printStackTrace();
}
System.exit(0);
}
}
can smebody hint where is my problem ? and why ?
cheers>
[3401 byte] By [
sscmita] at [2007-10-2 5:40:11]

javax.swing.text.html.parser.ParserDelegator does not have a method that takes your class as an argument since your class does not extend javax.swing.text.html.HTMLEditorKit.ParserCallback class...
as noted by the API for ParserDelegator...
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet)
Parse the given stream and drive the given callback with the results of the parse.
- MaxxDmg...
- ' He who never sleeps... '
some of the problem is in this method...
public void handleText(char[] data,int pos)
here you list all the files in a directory...
File directory=new File(".");
String[] files=directory.list();
then you create a new PrintWriter with new filename + "txt" for each file that was listed in the directory
PrintWriter pw=new PrintWriter(new (new BufferedWriter(new FileWriter(files[i]+"txt")));
pw.println(data);
pw.close();
so each time this method is called, a new file is created from the list of every files in the directory and more get made... and is only writing what ever the current char array holds when the parser calls this method...
and the parser calls handleText() method for each line in the file it's reading...
also you want to only read the html files, your current setup parses through every file in the directory too... so basically you created a massive infinite loop...
- MaxxDmg...
- ' He who never sleeps... '