简体   繁体   中英

Creating a configuration.yml file

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM