Linux komut satırından bir metin dosyasını Java programıma kabul etmeye çalışıyorum ancak derleyici bana başlıkta belirtilen hatayı veriyor. Hata, "String fileName = args [0];" yazan satırda meydana geldiğini söylüyor. Birisi neden olduğunu biliyor mu? İşte benim kodudur:ArrayIndexOutOfBoundsException: 0, Java'daki Linux komut satırından bir dosyada okumaya çalışırken ortaya çıkar?
public class Parsons_Decoder
{
// method: main
// purpose: receives key-phrase and sequence of integers and
// prints the secret message to the screen.
public static void main(String[] args) throws IOException
{
String fileName = args[0];
// reads incoming file (if it exists) and saves the key-phrase to
// String variable "keyPhrase"
File testFile = new File(fileName);
if(!testFile.exists())
{
System.out.println("\nThis file does not exist.\n");
System.exit(0);
}
Scanner inputFile = new Scanner(args[0]);
String keyPhrase = inputFile.nextLine();
// creates an ArrayList and stores the sequence of integers into it
ArrayList<Integer> numArray = new ArrayList<Integer>();
while(inputFile.hasNextInt())
{
numArray.add(inputFile.nextInt());
}
// decodes and prints the secret message to the screen
System.out.println();
System.out.print("Your secret message is: ");
for(int i = 0; i < numArray.size(); i++)
{
int num = numArray.get(i);
System.out.print(keyPhrase.charAt(num));
}
System.out.println("\n");
//keyboard.close();
inputFile.close();
}
}
Programı nasıl çalıştırıyorsunuz? Argümanlar ile tam komut lütfen – 3kings
CLI'de neler yazıyorsunuz? – Gendarme
Bunun için üzgünüm, komut satırı olmalıdır: java Parsons_Dedocer
thelonewanderer