Scaning a document
Respected sir,
i am facing a problem with scaning a document using java code....i want to know .
one morething is how much data it can scan at a strech.
Basically in my project there's is a log file...... which is consisting of my project errors.....i want to scan that particular log file using java code.
I don't know what exactly you want to scan from document. Here is an example of calculating word frequency.
import java.io.*;
import java.util.*;
public class WordFrequency {
static public void main(String[] args) {
Map words = new HashMap();
String delim = " \t\n.,:;?!-/()[]\"\'";
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line, word;
Count count;
try {
while ((line = in.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, delim);
while (st.hasMoreTokens()) {
word = st.nextToken().toLowerCase();
count = (Count) words.get(word);
if (count == null) {
words.put(word, new Count(word, 1));
} else {
count.i++;
}
}
}
} catch (IOException e) {}
Set set = words.entrySet();
Iterator iter = set.iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
word = (String) entry.getKey();
count = (Count) entry.getValue();
System.out.println(word + (word.length() < 8 ? "\t\t" : "\t") + count.i);
}
}
}
class Count {
Count(String word, int i) {
this.word = word;
this.i = i;
}
String word;
int i;
}