Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

counting  RSS feed

 
Sandeepan Sarkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to java.
Please help me with these two questions:
1. How to count no of words in a file.
2. How to list all the files present in an particular directory.
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, cool sandy. We are a friendly bunch here, so we ask that you use your real name. As our Naming Policy states, accounts with obviously fictitious names will be closed.
You can change your displayed name here.
Thanks.
The questions you are asking are pretty basic. Since there's a chance you may be working on homework, I'm going to steer you in the right direction, but leave the work up to you.
For your first question, in order to count the number of words in a file, first you have to read the file. The Java Tutorial has a chapter on Input/Output. Give it a read.
For your second question, the file system in Java is represented by the java.io.File object.
Give your tasks a try and we'll be here if you have any more questions.
BTW, it's "Heaven doesn't want me. Hell's afraid I'll take over"
 
Harald Kirsch
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you've changed your display name, you will face the problem of defining what a word is. Brca1 is the name of a cancer related gene. Would you call it a word? How about 1,2,3-Propanetriol, is it a word? And don't forget to think about '90%' or $321.12. Are these words?

Good luck
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!