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]
# 1
I am sorry for the wrong subject line in my posting
sscmita at 2007-7-16 1:50:31 > top of Java-index,Java Essentials,Java Programming...
# 2

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... '

MaxxDmga at 2007-7-16 1:50:31 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi MaxxDmg.

Thanks a lot for rectifying my stupid mistake. I have still one more mistake in my loop (I presume) which I failed to figure out. As a result it compiles and runs but I am getting 100s(multiple copies) of copies of a single html file , I think it is an infinity loop and each fie contains 0 byte.

can you please point out the wrong line of code

Thanks once again

sscmita at 2007-7-16 1:50:31 > top of Java-index,Java Essentials,Java Programming...
# 4

you code simple reads all the files in the directory and tries to parse them and add the txt to the name... if you have just one file, as it processed, a new one is created and then that one is processed, and yet another is created and that is processed... ad infintum...

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:50:31 > top of Java-index,Java Essentials,Java Programming...
# 5
to top it off, your hand text method pretty much writes to all the files too... and adds txt to the end, so new files pop up for it to write to and add txt to...- MaxxDmg...- ' He who never sleeps.. '
MaxxDmga at 2007-7-16 1:50:31 > top of Java-index,Java Essentials,Java Programming...
# 6
You are absoutely Right MaxxDmg !But if you dont mind can you please tell me which is the culprit line and how I can change it ,I mean replace it and where ?sorry for these naive questions but I am not very well versed in programming yet.cheers
sscmita at 2007-7-16 1:50:32 > top of Java-index,Java Essentials,Java Programming...
# 7

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... '

MaxxDmga at 2007-7-16 1:50:32 > top of Java-index,Java Essentials,Java Programming...
# 8
Thank you very much indeed for your time.I will try to correct it.
sscmita at 2007-7-16 1:50:32 > top of Java-index,Java Essentials,Java Programming...