Fathi
HTMLParserText
1 Answer(s)      3 years and a month ago
Posted in : Java Interview Questions

Thanks for the file that you send me. But my problem, i want to convert it from HTML to TXT file. This means I have to remove all tags. In this way, I need your helpful.

With my best regards
View Answers

April 29, 2010 at 3:14 PM


Hi Friend,

Try the following code:

import java.io.*;
public class ReadHTML{
public static void main(String[]args){
try{
File file = new File("applet.html");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
String st="";
while (dis.available() != 0) {
st+=dis.readLine().toString()+"\n";
}
String str=st.replaceAll("[\"]"," ").replaceAll("[/<>.=]"," ");

File f = new File("hello.txt");
FileWriter fstream = new FileWriter(f);
BufferedWriter out = new BufferedWriter(fstream);
out.write(str);
out.close();
}
catch(Exception e){}
}
}

Hope that it will be helpful for you.
Thanks









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.