Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read Java Script file in simple java

 
Prathap Krishnamurthy
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Need to know how to read Java script file in simple java.
After that need to find commented parts(ex:/**,//...etc) in JS and need to remove it
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaScript file is just a plain text file. You could simply read the file line by line.

Finding comments could simply be done with String.indexOf(), or with regular expressions. You'd probably need to be a little bit more sophisticated than just search for /* or //, because those characters could also appear inside a JavaScript string literal, in which case they don't represent the beginning of a comment. Also, I don't know how JavaScript deals with nested comments:

/* Hello world /* Nested comment */ Some more text */

Does the first or the second */ indicate the end of the comment? You'd have to look that up somewhere in a JavaScript specification.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic