I've tried to use the CMD console instead of using Eclipse's console because I wanted to try to do a simple animation ('|', '/', '-', '\') and couldn't find a way to clear the screen on Eclipse's console.
After exporting my code into a Runnable Jar file, I opened it on the CMD console using java -jar test.jar but I get a FileNotFoundException.
To help debug my code, I've tried compiling it on Eclipse. This is the following output:
|/-\|/-\|/-\
Note: between each string output has a 500 ms delay.
public void doAnimation(String animation) {
try {
BufferedReader br = new BufferedReader(new FileReader( new File("res/animations.txt")));
String current = null;
boolean exit = false;
while((current = br.readLine()) != null && !exit) {
if(current.toLowerCase().equals(animation.toLowerCase())) {
String[] frames = br.readLine().split(" ");
int repeat = 3;
for(int r = 0; r < repeat; r++) {
for(int i = 0; i < frames.length; i++) {
clearConsole();
print(frames[i]);
Thread.sleep(500);
}
}
exit = true;
}
}
br.close();
} catch (FileNotFoundException e) {
print("Could not find animation file.");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
I expected a simple rotating stick animation but instead it wouldn't find the text document.