import java.io.*;
import java.util.StringTokenizer;
class FileCopy
{
public static void main(String[] args) throws IOException
{
String infile = null;
String outfile = null;
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
if (args.length >= 2) //both files given via command line
{
infile = args[0];
if (fileExists(infile) == false)
{
infile = getInputFile();
}
outfile = args[1];
}
else if (args.length == 1) //input file given via command line
{
infile = args[0];
outfile = getOutputFile();
}
else //no files given on command line
{
infile = getInputFile();
outfile = getOutputFile();
}
//create file objects to use
File in = new File(infile);
File out = new File(outfile);
/*
*rest of code
*/
}
//get the input file from the user if given file does not exist
public static String getInputFile() throws IOException
{
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String fileName = null;
boolean haveFile = false;
do
{
System.out.println("Enter a valid filename:");
System.out.print(">> ");
fileName = stdin.readLine();
haveFile = fileExists(fileName);
}while(haveFile == false);
return fileName;
}
//get the output file and test things
public static String getOutputFile()
{
return null;
}
//check the given file to see if it exists in the current working directory
public static boolean fileExists(String n)
{
boolean exist = false;
if (n.length() != 0)
{
File tmp = new File(n);
exist = tmp.exists();
}
return exist;
}
}
53 行目で fileExists を呼び出すときに問題が発生します。構文は、私が知る限り正しいですが、do ループに無期限にとどまります。Jcreator でプログラムをステップ実行しても解決策は見つかりませんが、興味深いことに、プログラムは fileExists にジャンプせずに 53 行目まで進みます。何が間違っているのですか?