Hello all,
I have a small program that has a method which uses the File class and it's exists() method. Unfortunately I think I'm constructing it wrong or something because I get a compile-time error saying that my constructor is an invalid statement. Can someone tell me the correct way to do it? My snippet of code is below so you can kind of see what I'm attempting to do. It takes in a file name (i.e. "temp.txt" and checks to see if it exists or not.
Thanks,
Jisoo22
I have a small program that has a method which uses the File class and it's exists() method. Unfortunately I think I'm constructing it wrong or something because I get a compile-time error saying that my constructor is an invalid statement. Can someone tell me the correct way to do it? My snippet of code is below so you can kind of see what I'm attempting to do. It takes in a file name (i.e. "temp.txt" and checks to see if it exists or not.
Thanks,
Jisoo22
Code:
import java.io.*;
public class simModel_2_1 {
public static void main (String args[])
{
String fileName = "world.txt";
fileName = checkReadFile(fileName, args);
System.out.println(fileName);//debugging
}
public static String checkReadFile(String file, String [] args)
{
String temp;
String str;
if (str.length() > 0)
{
temp = str;
}
else
{
temp = file;
}
while (temp.equalsIgnoreCase("q") == false)
File f = new File(temp);
if(f.exists() == true)
{
return temp;
}
else
{
System.out.println("The simulation data file " + temp +
"cannot be read.");
System.out.println("Enter a new file name or 'Q' to quit: ");
str = Keyboard.readString();
}
}//checkReadFile
}//class simModel_2_1
[code]