//Extract "I + don't + nextword" + "delete" repeated phrases //based on Daniel Shiffman code - week 1 - A2Z import java.io.*; import java.nio.*; import java.nio.channels.*; public class Exercise1{ public static void main (String[] args) throws IOException { // Create an input stream and file channel // Using first argument as file name to read in FileInputStream fis = new FileInputStream(args[0]); FileChannel fc = fis.getChannel(); // Read the contents of a file into a ByteBuffer ByteBuffer bb = ByteBuffer.allocate((int)fc.size()); fc.read(bb); fc.close(); // Convert ByteBuffer to one long String String content = new String(bb.array()); // This line uses a regular expression which we haven't learned yet // '\\b' means split the text along word boundaries // We will cover this in more detail next week String[] words = content.split("\\b"); // create a new string buffer ( that will store the words I + don't + nextword ) StringBuffer findI = new StringBuffer(); for ( int i=0; i< words.length;i++){ String find = "I"; if(words[i].equals(find)){ findI.append(words[i]+ " don't " + words[i+2] + " " + "\n"); } } // transform the StringBuffer to a String and then split each phrase into an Array String output1 = findI.toString(); System.out.println(output1); String [] phrases = output1.split("\n"); // Create new String Buffer ( to each the unique phrases will be appended) StringBuffer finali = new StringBuffer(); // temp String to compare content ( use contains -- cannot use any method for String Buffer?) String finali2= ""; for ( int b=0; b