我正在尝试使用java在文件中打印内容,这是代码
//open a file
public void openFileTwo(String file){
try{
y = new Scanner(new File(file));
}catch(Exception e){
System.out.println("Failed to find the file");
}
}
//here im trying to get a word and also bigram and store them in an array
public void readArticles(String file,ArrayList<String> storage) throws IOException{
openFileTwo(file);
while(y.hasNext()){
String a = y.next();
a = a.replaceAll("[^A-Za-z0-9]", "");
a = a.toLowerCase();
storage.add(a);
}
closeFile();
storage.removeAll(Arrays.asList(null,""));
int size = storage.size();
for(int i = 0; i < size; i++){
if(i != size-1){
storage.add(storage.get(i)+" "+storage.get(i+1));
}
}
//writeFile(storage, "D:/skripsi/perlengkapan/test.txt");
}
然后,我想运行它
FileWriter f0 = new FileWriter("D:/skripsi/perlengkapan/tfidf.txt");
String newLine = System.getProperty("line.separator");
//i call the readArticles method
f0.write(a +newLine);
readArticles(c,store);
只要我把readArticles方法放在上面就可以运行,任何人都可以帮助我吗?
提前致谢