I'm currently attempting to write a program that can scan a text document and replace a specified word / string / whatever with another phrase, specifically using the classes Scanner and Printwriter. Unfortunately, I'm having a little bit of trouble finding the correct methods to use and how exactly to implement them. Here's my code:
class Redaction { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(System.in); System.out .println("Please enter the filename of the sensitive information"); String f = input.next(); System.out.println("Please input what text you want 'lost'"); String o = input.next(); System.out .println("Please input what you want the new, improved filename to be called"); String n = input.next(); File sensitiveDocument = new File(f); if (!sensitiveDocument.exists()) { System.out.println("File does not exist."); System.exit(0); } Scanner in = new Scanner(sensitiveDocument); in.useDelimiter("[^A-Za-z]+"); PrintWriter out = new PrintWriter(n); while (in.hasNext()) { if (in.hasNext(o)) { // ... } } in.close(); out.close(); } } I'm pretty lost at this point. Any help would be much appreciated.
(in.hasNext(o))has no code in it. What are you confused about ?