Hey
sorry to double post but i am at my wits end trying to understand why my code is not working. I understand that there is very likely some simple problems that need fixing but this i do not need help with.
When i try to compile this it tells me it cannot find the
createNewFile()
and .exists() symbols but i made sure to import them correctly and unless i can no longer see the wood from the trees im stumped.
A bottle of guinness for the first fellow who can help
Thanks,
S.
Code:
import java.io.*;
import javax.swing.JOptionPane;
import java.util.*;
import java.util.Collections;
import java.io.File;
public class DictionaryProject
{
public static int count= 0;
public static String userInput= "", tempFile, dictFile;
public static String userMessage ="";
public static void main (String [] args) throws IOException
{
String message1= "1. Add word\n" + "2. Delete word \n" + "3. Search \n" + "4. List on screen dictionary entries\n" + "5. List secondary functions";
String message2= "1. Add your word now:\n " + "2. Finished creating(Return to main options menu)\n";
String message3= "1. Delete word now:\n" + "2. Finished destroying (return to main menu)\n";
String message4= "1. Search for your word now:\n" + "2. Finished fishing (return to main menu)\n";
String message5= "Display the...\n" + "a. Number of words in dictionary.\n" + "b. Number of words that start with each letter of the alphabet\n" + "c. Number of pallidromes within dictionary\n" + "d. The shortest word\n" + "e. The longest word\n";
String pattern1= "[0-9, A-Z, a-z] {1,}.txt";
String pattern2= "1|2|3|4|5";
String pattern3= "a|b|c|e";
String temporaryFile, dictionaryFile, result;
Vector preDictionaryList = new Vector();
dictionaryFile = JOptionPane.showInputDialog(null, "Enter the name of your dictionary file now: /n");
temporaryFile = JOptionPane.showInputDialog(null, "Enter then name of your temporary file now: /n");
temporaryFile = temporaryFile.toLowerCase();
dictionaryFile = dictionaryFile.toLowerCase();
if (!(dictionaryFile.matches(pattern1) || temporaryFile.matches(pattern1)))
{
result = "The file name entered does not match the required criteria, please ensure your filenames are spelt correctly.";
}
else
{
File dictFile = new File (dictionaryFile);
File tempFile = new File (temporaryFile);
}
if( !(dictFile.exists() || tempFile.exists()))
{
result = "File does not exist, Creating file now";
dictFile.createNewFile();
tempFile.createNewFile();
FileWriter fw1 =new FileWriter(dictFile);
FileWriter fw2 =new FileWriter(tempFile);
BufferedWriter bw1 = new BufferedWriter(fw1);
BufferedWriter bw2 = new BufferedWriter(fw2);
}
else
{
FileWriter fw1 =new FileWriter(dictFile);
FileWriter fw2 =new FileWriter(tempFile);
BufferedWriter bw1 = new BufferedWriter(fw1);
BufferedWriter bw2 = new BufferedWriter(fw2);
}
}