files in java

Started by
2 comments, last by Toasted 22 years, 7 months ago
Hello kind people... Ive have the enoumous task (yeah right) of making hangman in Java, however my knowledge of Java is somewhat limited. I can compile my program ok but when running the following error is in the taskbar exception com.ms.security.SecurityExceptionEx[hangman.openFile]: cannot access file hangmanWords.txt I originally thought this had something to do with security settings in IE5 but having lowered then to nill it still doens''t work. Any help would be appreciativee. public void openFile() { // OPEN FILE and READ FILE try { hangmanFile = new BufferedReader(new FileReader(filename)); word = hangmanFile.readLine(); hangmanFile.close(); } catch(IOException e) { System.err.println("Can''t find file words.txt"); return; } } openFile(); is in public void init()
Advertisement
I am not a Java expert but it looks like it can''t open the words file
It looks like it can''t open the words file
try the microsoft website
This uses a different way, but this is how I read from files...


public void LoadMap(String newMap)
{
URL url;
InputStream stream;
StreamTokenizer tokenizer;

try
{
url = new URL(getCodeBase(), newMap); //here newMap is the name of the file to be read
}
catch(final MalformedURLException e)
{
return;
}

try
{
stream = url.openStream();
}
catch(final IOException e)
{
return;
}

tokenizer = new StreamTokenizer(stream);

tokenizer.wordChars(0, '' '');
tokenizer.whitespaceChars(''\n'', '' '');

int token;

try
{
token = tokenizer.nextToken();
}
catch(IOException e)
{
return;
}

//Read in until we''ve reached the end of the file
while(token != tokenizer.TT_EOF)
{
switch (token)
{
case tokenizer.TT_NUMBER:
//A number was read in, so if you say wanted
//to assign it to the variable i you would do..
i = (int)tokenizer.nval;
break;
case tokenizer.TT_WORD:
//Then we read in a word so do whatever you wanna
//do with that, maybe you want to save it to String x;
x = tokenizer.sval;
break;
}
try
{
token = tokenizer.nextToken();
}
catch(IOException e)
{
return;
}
}


By the way, if anyone knows how you make those code boxes could you please post how..

-lao

This topic is closed to new replies.

Advertisement