'Code doesnt put anything out when comiling
Hey guys for some reason my code doesn't do anything when I compile it and I would appreciate if someone can figure it out, i am not very knowledgeable in java and coding in general and i tried fixing it and i got nothing i thought maybe it was the bufferedreader or the filereader but I'm not sure, so here is my code below
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Driver2 {
public static ArrayList < String > removeStopWords(String DTP3, String stopwords) throws IOException {
ArrayList < String > wordlst = new ArrayList < String > ();
ArrayList < String > stopwordlst = new ArrayList < String > ();
BufferedReader br1 = new BufferedReader(new FileReader("DTP3.txt"));
String line = "";
while ((line = br1.readLine()) != null) {
String[] words = line.split("[ ().!,:]");
for (int i = 0; i < words.length; i++) {
if (words[i].trim().equals("") == false) {
wordlst.add(words[i]);
}
}
}
br1.close();
ArrayList < String > wordlstUpper = new ArrayList < String > ();
for (int i = 0; i < wordlst.size(); i++) {
wordlstUpper.add(wordlst.get(i).toUpperCase());
}
BufferedReader br2 = new BufferedReader(new FileReader("stopwords.txt"));
line = "";
while ((line = br2.readLine()) != null) {
stopwordlst.add(line);
}
br2.close();
for (int i = 0; i < stopwordlst.size(); i++) {
int lastindex = wordlstUpper.indexOf(stopwordlst.get(i).toUpperCase());
while (lastindex != -1) {
int index = wordlstUpper.indexOf(stopwordlst.get(i).toUpperCase());
if (index != -1) {
wordlst.remove(index);
wordlstUpper.remove(index);
}
lastindex = wordlstUpper.indexOf(stopwordlst.get(i).toUpperCase());
}
}
return wordlst;
}
public static void main(String[] args) {
ArrayList < String > list = null;
try {
list = removeStopWords("GPT3.txt", "stopwords.txt");
} catch (IOException e) {
System.out.print("Error : " + e.getMessage())
}
System.out.println("Non Stop Words are----");
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
