File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to read Java Script file in simple java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to read Java Script file in simple java" Watch "How to read Java Script file in simple java" New topic

How to read Java Script file in simple java

Prathap Krishnamurthy

Joined: Oct 28, 2005
Posts: 17

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

Prathap Krishnamurthy
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link:
subject: How to read Java Script file in simple java
Similar Threads
Rich Faces Calendar
Parsing scripts files through java
Java 7 Beginner's Tutorial and scripting on the JVM
executing perl scripts from java
Need a rollover effect when UIComponent is disabled and vice versa