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

read file replace string  RSS feed

 
nirail rail
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to read all files in directory
in file i want to search for a particular string all occurence
make a new line on bases of this line and replace it with old one
how this can be done

for example
i have .jsp file i want to replace
"<jsp:useBean id="schemeBean" scope="page" class="com.xyz.scheme"/>"

with

<%@ page import="com.xyz.scheme" %>
"<jsp:useBean id="schemeBean" scope="page" class="com.xyz.scheme"/>"

pls help
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try by using the File class.

Start with making a file object using the directory. You can use this object to get each file in the directory. Make easch file in the directory into a file object. Then read each file line by line comparing it to the given string. Then you can manipulate the file when you find the string you are looking for.

The File class has all the methods you need to navigate through the folder and the FileInputStream and FileOutputStream are a good place to start with the file handling

Rachel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!