0

I am working on a project and I would like to know how to store data in a file, preferably a YAML file.

I have created a Swing GUI for creating an account, which contains a Username JTextPane and a Password JPasswordField, a Create JButton, and an Output.

I want it to work so that when I press the button, an ActionListener is called which will write the username and password to an accounts.yml file, which would look like this:

usernames:
  leviathan: "password"

Don't worry about encryption, I will take care of that later. All I ask for is how to implement this YAML file and write to it in the code.

Zong
  • 6,160
  • 5
  • 32
  • 46
Leviathan
  • 83
  • 1
  • 3
  • 13

1 Answers1

1

Java does not have pre-defined functions for writing yml files. You'd have to do one of the following:

Use a Library

Check out this question to see if some of these libraries would work for you.

Writing Manually

Creating a YAML file would be the same as creating any other type of file. For an example, see this question. You just want to set the output as *.yml instead of *.txt and when you write each line you would want to make sure to write it in the correct format.

Community
  • 1
  • 1
DoubleDouble
  • 1,493
  • 10
  • 25