導入大量單詞,我需要創建能識別文件中每個單詞的代碼。我正在使用分隔符來識別每個單詞的分隔,但我收到一個壓縮錯誤,指出未使用linenumber和分隔符的值。我需要做些什麼才能讓程序讀取該文件並分離該文件中的每個單詞?識別文件中的每個單詞
public class ASCIIPrime {
public final static String LOC = "C:\\english1.txt";
@SuppressWarnings("null")
public static void main(String[] args) throws IOException {
//import list of words
@SuppressWarnings("resource")
BufferedReader File = new BufferedReader(new FileReader(LOC));
//Create a temporary ArrayList to store data
ArrayList<String> temp = new ArrayList<String>();
//Find number of lines in txt file
String line;
while ((line = File.readLine()) != null)
{
temp.add(line);
}
//Identify each word in file
int lineNumber = 0;
lineNumber++;
String delimiter = "\t";
//assess each character in the word to determine the ascii value
int total = 0;
for (int i=0; i < ((String) line).length(); i++)
{
char c = ((String) line).charAt(i);
total += c;
}
System.out.println ("The total value of " + line + " is " + total);
}
}
...這是所有的代碼? – Pimgd
@Pimgd編輯添加我的所有代碼 – mrsw
格式化它,因此它對我來說是可讀的... – Pimgd