/** Class oppgave1b* By Rune Vikestad* E-Mail vikestad@stud.ntnu.no* Web http://folk.ntnu.no/vikestad/* Description IT-1103, Basic Programming (Java), Exercise 6*/import java.io.*;import java.util.*;import javax.swing.JOptionPane;/*** Class: 'oppgave1b'*/public class oppgave1b { /** * Method: 'main'. */ public static void main(String[] args) throws IOException { /* * Variable Declarations */ FileReader fr; FileWriter fw; PrintWriter pw; String fileInName; // The name of the file we read from String fileOutName; // The name of the file we write to int charCode; // The decimal value of a character read char wordPart; // The alphanumeric value of a character read. String wordTemp = ""; // The temporary string used to store words, before they're processed into an array. int counter = 0; // We use this integer to count how many words we've read, for the array. String[] wordArray; // Our words, in an array. boolean wordExists; /* * Variable Initiations */ fileInName = JOptionPane.showInputDialog("File name: "); fileOutName = JOptionPane.showInputDialog("File name (Output): "); fr = new FileReader(fileInName); fw = new FileWriter(fileOutName); pw = new PrintWriter(fw); wordArray = new String[100]; wordExists = false; /* * Process our stream. */ do { charCode = fr.read(); /* If character isn't a Comma, Period, Space or EOF. */ if (charCode != 46 && charCode != 44 && charCode != 32 && charCode != -1) { if (charCode >= 65 && charCode < 97) { /* Found an upper case character, so make it lower case. */ charCode = charCode + 32; } /* Insert the character into our temporary word */ wordPart = (char)charCode; wordTemp = wordTemp + wordPart; } if (charCode == 32 || charCode == -1) { /* We found a space or the EOF, which means we've got a word. */ for (int i=0;i<counter;i++) { /* Check if the word we found, exists in our array. */ if (wordTemp.equals(wordArray[i])) { wordExists = true; } } if (wordExists == false) { // The word doesn't exist in our array, so store it, print it and save it to the file. wordArray[counter] = wordTemp; System.out.println(wordArray[counter]); // Print to screen. pw.println(wordArray[counter]); // Print to file. wordTemp = ""; counter = counter+1; } else if (wordExists == true) { // The word exists in our array, so discard it. wordExists = false; wordTemp = ""; } } } while (charCode > 0); fr.close(); fw.close(); pw.close(); System.exit(0); }}