Hi everybody.. i have a java program to convert Html to text file... but i want to call a stanford-postagger jar file to my java pgm.. could anybody help me..
HERE IS MY JAVA PROGRAM TO CONVERT HTML TO TXT
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.File;
public class conv {
public static void main(String[] args) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader("C:/1.html"));
String line;
while ( (line=br.readLine()) != null)
{
sb.append(line);
}
try
{
String nohtml = sb.toString().replaceAll("\\<.*?>","");
PrintStream out = new PrintStream(new FileOutputStream("C:/Out.txt"));
StringTokenizer st = new StringTokenizer(nohtml);
while (st.hasMoreTokens())
{
out.println(st.nextToken().toString());
}
Scanner scan = new Scanner(System.in);
System.out.print("Enter File Name:");
String file_Name = "C:/"+scan.nextLine();
//System.out.print("Enter Starting Word:");
String start_word = "Good";
//System.out.print("Enter Final Word:");
String end_word = "Views,";
conv file = new conv();
String word = file.showLines(file_Name, start_word,end_word);
System.out.println(">>>");
if(word.length()>1)
{
//System.out.println(word);
String[] words = word.split("\\,");
for (String str : words)
{
System.out.println(str);
try
{
PrintStream out1 = new PrintStream(new
FileOutputStream("c:/sampleoutput.txt"));
for (String astr : words)
{
out1.println(astr);
}
out1.println();
out1.close();
}
/*StringTokenizer stg = new StringTokenizer(word, ".");
File newFile = new File("c:/newWords.txt");
try {
BufferedWriter writer= new BufferedWriter(new FileWriter(newFile,true));
while(stg.hasMoreTokens()) {
String val = stg.nextToken().trim()+".";
System.out.println(val);
writer.append(val);
writer.newLine();
}
writer.close();
}*/
catch (Exception e)
{
// e.printStackTrace();
System.out.println(e);
}
}
}
else
System.out.println("### Not Found");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
public String showLines(String fileName, String start, String en开发者_如何学JAVAd) {
String word = "";
try {
Scanner scan = new Scanner(new File(fileName));
while(scan.hasNext())
{
if(scan.next().equals(start))
{
word = start;
while(scan.hasNext())
{
String test = scan.next();
word = word +" "+ test;
if(test.equals(end))
break;
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return word;
}
}
Just put the jar file in your classpath and import the required Class in your program.
Add the jar file to your classpath and call the main() function in it.
In order to use a jar, aka, to be able to import the classes of an external jar in the classes of your own project you have to place that jar in the class path. Putting it in the classpath boil down to multiple options:
either you declare a CLASSPATH system environment variable, and in there you specify a folder where your external jar will be placed, this way when you compile your code the jar will be available in the compiler
you declare the classpath folder containg the external jar at compile time using the "classpath" flag:
javac -classpath /path/to/dir/with/jars/ MyMainClass
Once a jar file is included in your project lib directory, any class within the jar can be called/imported as though they were your own. You will not be able to edit the included files, but you will have full access to their functionality.
精彩评论