我是这个很棒的地方的新手。我从这个网站得到了几次帮助。我已经看到了很多关于我之前讨论过的问题的答案,但是我在使用 FileReader 计算字符数时遇到了问题。它正在使用扫描仪工作。这是我尝试过的:
class CountCharacter
{
public static void main(String args[]) throws IOException
{
File f = new File("hello.txt");
int charCount=0;
String c;
//int lineCount=0;
if(!f.exists())
{
f.createNewFile();
}
BufferedReader br = new BufferedReader(new FileReader(f));
while ( (c=br.readLine()) != null) {
String s = br.readLine();
charCount = s.length()-1;
charCount++;
}
System.out.println("NO OF LINE IN THE FILE, NAMED " +f.getName()+ " IS " +charCount);
}
}`