Hi there, this is my first post on the forum, and i'm relatively new to java. Anyways, i've just spent the last few hours looking for answers in my university textbook and the sun website, and im at a loss, so any help provided would be lovely, and thanks in advance.
Anyways, my project is to create a "find and replace" program simliar to those in microsoft word, etc. The only problem i've ran into so far is that i get an error with the code that i have in public void actionPerformed (ActionEvent e)
its telling me that i haven't set anything up to handle a fileNotFoundExc eption, which makes sense because from my understanding, you can't throw an exception with actionPerformed ? So i saw on previous forums to use a try, catch, but im still having problems. any suggestions? My code is below
Anyways, my project is to create a "find and replace" program simliar to those in microsoft word, etc. The only problem i've ran into so far is that i get an error with the code that i have in public void actionPerformed (ActionEvent e)
its telling me that i haven't set anything up to handle a fileNotFoundExc eption, which makes sense because from my understanding, you can't throw an exception with actionPerformed ? So i saw on previous forums to use a try, catch, but im still having problems. any suggestions? My code is below
Code:
public void actionPerformed(ActionEvent e) { String find = findTextField.getText(); String replace = replaceTextField.getText(); try { FileReader fReader = new FileReader("Readme.txt"); BufferedReader inputFile = new BufferedReader(fReader); } catch(FileNotFoundException a) { JOptionPane.showMessageDialog(null, "File not found."); } String line = inputFile.readLine(); System.out.println("New text: \n"); while (!(line == null)) { while(line.indexOf(find) != -1) { String [] words = line.split(find); line = (words[0].concat(replace).concat(words[1])); } System.out.println(line); line = inputFile.readLine(); } }
Comment