ich ein komplettes Java-Programm, aber die Art und Weise, dass mein Professor überprüfen wird, um sicherzustellen, dass das Programm korrekt funktioniert durch CMD ist
"java Caesar input.txt output.txt"
Fehler in der Befehlszeile, während Java-Programme laufen
Aber die Probleme, denen ich bin, sind, dass wenn ich mit "javac Caesar.java
" kompilieren wird es eine Caesar.class
Datei im Ordner kompilieren und erstellen, aber wenn ich es als "" ausführen, heißt es Fehler: Could not find or load main class caesar
.
Was mache ich hier falsch?
Ich kann zusätzliche Informationen bei Bedarf bereitstellen.
package caaesar;
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;
/**
*
* @author Connorbboggs
* Version 12.03.2017
*/
public class Caaesar
{
private static Scanner sc;
private static FileWriter fw;
private static BufferedWriter bw;
private Scanner inp;
private Scanner outp;
//DecodeChar class provided by you
public static char decodeChar(int n, char ch)
{
int ord;
if (ch >= 'A' && ch <= 'Z')
{
ord = ch - 'A';
ord += n;
ord %= 26;
return (char)(ord + 'A');
}
else if (ch >= 'a' && ch <= 'z')
{
ord = ch - 'a';
ord += n;
ord %= 26;
return (char)(ord + 'a');
}
else
{
return ch;
}
}
public static void main(String[] args)
{
//File input for decode.txt with the encrypted text
File inputFile = new File(args[0]);
//Output for the decrypted text
File outputFile = new File(args[1]);
try
{
//input from inputFile
sc = new Scanner(inputFile);
int shift = sc.nextInt();
String decoded = "";
//while lines are available text is fed to inputFile
while(sc.hasNextLine())
{
//Lines being fed into string line
String line = sc.nextLine();
//for loop to feed into decoded using decodeChar
for(int i=0; i<line.length(); i++)
{
decoded += decodeChar(shift, line.charAt(i));
}
decoded += '\n';
}
//Just to verify that the text is decrypted
System.out.println(decoded);
try
{
//create a fileWriter for outputFile
fw = new FileWriter(outputFile);
//write "decoded" to the file
fw.write(decoded);
//close the file
fw.close();
}
//exception catching
catch (IOException ex)
{
ex.printStackTrace();
}
}
//more exception
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}
Ein Großbuchstabe C unterscheidet sich von einem Kleinbuchstabe c. Hast du beides versucht? –
Alle Java-Bezeichner unterscheiden zwischen Groß- und Kleinschreibung. 'Caesar' und' caesar' sind nicht identisch. – Andreas
Richtig, das war ein Tippfehler, und die Verwendung von Groß- und Kleinbuchstaben liefert den gleichen Fehler. Hier ist ein Screenshot von genau, was los ist: https://gyazo.com/a39a5793fced9fc67b22abb22317957c – Ronave4C