import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.filechooser.*;public class textSearch { public static void main(String[] args) throws IOException { readFile (); } public static void readFile() throws IOException { JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // Application opens the file BufferedReader br = new BufferedReader(new FileReader(file)); // Loads file into the buffer printFile(br); } else { javax.swing.JOptionPane.showMessageDialog(null,"Open command cancelled by user."); // Printed if user cancels } } public static void printFile(BufferedReader br) throws IOException { String line = ""; String word = JOptionPane.showInputDialog(null,"Please specify the word you want to search for."); while(line != null) { line = br.readLine(); returnSearch(line,word); } } public static void returnSearch(String arg, String comp) { if(arg != null) { boolean result = false; int cnt = 0; int i = 0; int lnArg = arg.length(); int lnComp = comp.length(); String myString = ""; while(cnt + lnComp <= lnArg) { String sub = arg.substring(cnt, cnt + lnComp); result = sub.equals(comp); // System.out.println(sub+"--"+comp+"--"+result); // Uncomment the line above to see how the program searches for the specified string if (result == true) { // System.out.println(sub+"--"+comp+"--"+result); // Uncomment the line above to see how the program searches for the specified string System.out.println(arg); myString = new String(""); for (i=0; i < cnt; i++) { myString = myString + " "; } for (i = cnt; i < cnt+ lnComp; i++) { myString = myString + "*"; } System.out.println(myString); } cnt++; } } }}