Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package procesare;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Hashtable;
- import java.util.Map.Entry;
- import java.util.Hashtable.*;
- public class ExceptionsAndStopWords {
- //hash table pentru stocarea cuvintelor si nr de apritii ale lor
- private Hashtable<String, Integer> table = new Hashtable<String, Integer>();
- //constructorul
- public ExceptionsAndStopWords() {}
- //functia care returneaza un buuffered reader pe baza unui fisier dat ca parametru
- public BufferedReader OpenFile(String name)
- {
- try
- {
- File file = new File(name);
- FileReader fr = new FileReader(file);
- BufferedReader br = new BufferedReader(fr);
- return br;
- }catch (IOException e) {
- e.printStackTrace();
- BufferedReader br = null;
- return br;
- }
- }
- //functia care creaza un hashtable
- public void CreatingHashTable()
- {
- BufferedReader br = OpenFile("C:\\Users\\Gabi Socea\\Desktop\\Java\\RIW - Aplicatii\\Laborator_1\\Count_words\\file_input.txt");
- int c = 0;
- String words="";
- try
- {
- while((c = br.read()) != -1)
- {
- char ch = (char) c;
- if((ch >= 'A' && ch<='Z') || (ch>='a' && ch<='z') || (ch>='0' && ch<='9'))
- {
- words+=ch;
- }
- else
- {
- if(words.length() >= 1)
- {
- Integer count = table.get(words);
- table.put(words, count == null ? 1 : (count+1));
- }
- words = "";
- }
- }
- }catch (IOException e) {
- e.printStackTrace();
- }
- }
- //functia care afiseaza Hash Table-ul
- public void DisplayHashTable()
- {
- for(Entry<String, Integer> entry : table.entrySet())
- {
- System.out.println(entry.getKey() + "\t" + entry.getValue());
- }
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement