0

I have a question regarding java io*.

How can I input things into the java console, which after inputting gets added to the java file linked to.

The problem is that I need to create a people database, for which I can create a new Person, with email, number etc (of course only if this information is available to me, so that I can create that person's profile. I know how to link a text file to my java file and also display the content of it in the console, but in order to do that I only know how to add that output to the java source code. But I need to be able to create new persons entries in the console.

Easy said: I am a bank manager and only have the console to create a new people database but I do not have access to the source code. I hope the problem here is clear. Thanks in advance.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
mogli
  • 1

1 Answers1

1

Not 100% sure, but I assume:

  1. you would like to use the console as an input for your Java application,
  2. and then using this input to create Person objects
  3. and then save it into a database or to a text file.

It is a common use case in Java, please check this example. You have many options basically to achieve this, for example:

        // Using System Console to read inputs from users
        String line = System.console().readLine();
 
        System.out.println("Entered string " + line);

If you manage to understand this, and so read a line from input, then you can check this name, or command, you can create if/else, and other instructions and you can create objects from the inputs.

You can also create while or for loops until the given command is not good.

I hope I understand good your question.

czupe
  • 4,740
  • 7
  • 34
  • 52
  • 1
    Yes the Console class provides methods for data entry, even with text prompts. And even for passwords. This will in general not work in the fake IDE "console" window, but on the command line. Appending to a file was asked too. But one cannot do all. – Joop Eggen Jun 17 '22 at 21:55