私はテキストファイルの文字数を数えようとしています。しかし、行の最後には\ r \ nではなく、文字と空白だけを数えることができます。どのように含めることができますか? 以下の関数は、ファイル内の行数、単語数、および文字数をカウントします。行末を含むDOSテキストファイルの文字をカウントするには?
public static void Count(String FILENAME, int n) throws IOException {
inFile = new BufferedReader(new FileReader(FILENAME));
String currentLine; //= inFile.readLine();
while ((currentLine=inFile.readLine()) != null) {
lines[n]++;
bytes[n]+=currentLine.length();
bytes[n]++;
String[] WORDS = currentLine.split(" "); // split the string into sub-string by whitespace
// to separate each words and store them into an array
words[n] = words[n] + WORDS.length;
if (currentLine.length()==0)
words[n]--;
}
}
がなく(読み取り)整数を返し、Iは、文字列が必要です行を単語に分割する –