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

count html files thru java code  RSS feed

 
boli srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
50,000 html files are in a folder on a windows machine.Among them,content of some files
(not the file names )contain the sentence "SocioMaC-Jus' Follow!".Write a java program
to count the no of such files.
Can anyone please help?
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a homework problem and we ask that you do your own homework. Have you tried to write some code? We'd be glad to help you if you can provide us with some code to talk about.
 
boli srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I m a newbie in JAVA .I m still trying to be efficient with coding.I have tried to code something in which fistly i m counting the number of files and ythen reading each file through scanner..the draft looks something like this:


int len = new File(<directory path>).listFiles().length;
int count=0;
for (int i=1;i<<len;i++)
{
Scanner in = new Scanner (txt file);
try (
while in.hasNext()
{
String fulltext = in.next ();
if fulltext.contains("SocioMaC-Jus' Follow!") count=count+1;
}
) catch(Exception ex)
{
System.out.println(ex.getMessage());
}

Finally (
in.close ();
)
}>
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. (Your code would be more readable if you had posted it in the code tags -- see the "Code" button up there above the box you posted in? -- but anyway it's short so it's not totally impossible.) That looks sort of all right. Do you have a question about it? Because the usual way to find out if a program is working correctly is to run it and see if it works correctly.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!