Good evening. There was a problem that I can not implement. There is an application that reads the number of files in the specified folders and subfolders. Data for all folders the application reads simultaneously.

Actually the question is, you need to add functionality that allows you to stop counting files in all directories when you press the ESC button on the keyboard and not lose the already processed data.

And is it possible to stop the application in this way, if it is launched through the command window (Windows console)? Or can it be stopped only if it is launched through the development environment?

If anyone knows how to implement, help)

  • Do you need a code or an idea to send you? - Senior Pomidor
  • send, I think it will be enough) - Nekit Nekrasov
  • one stream reads files. and each time the loop passes, it checks some flag, for example, isContinue. Another stream listens to the keylistener on pressing the ESC button. and if clicked, it changes the state isContinue = false. - Senior Pomidor
  • Thank you for your comment. For me personally, there is nothing wrong with asking / directing. You don't know everything from birth, but somewhere you find information, read it, ask someone, right? I did not ask for a solution, thanks! - Nekit Nekrasov
  • @Senior Pomidor I am just trying to implement it. Thanks - Nekit Nekrasov

1 answer 1

Stopping the console application by pressing the esc key is not possible. We'll have to hang a transparent form and the listener will already hang on it.

 frame = new JFrame("KeyPress"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 27) { // do something here } } @Override public void keyReleased(KeyEvent e) { } }); frame.setOpacity(0.0f); frame.setVisible(true);