I want to have an INI file with a section containing a bunch of option values with the same option key. In othe rwords, I want to represent an array in the ini file. My problem is that only the last value is read into the array or liste, depending on the getAll method I use:
The .ini file:
[FTP]
; Access FTP server?
active = false
file.pattern = VA_.*.(csv|dat)$
#file.pattern = VA_.*(\\.(?i)(csv|dat))$
delete.after.download = false
[SFTP]
; Access FTP server?
active = true
file.pattern = VA_.*.(csv|dat)$
#file.pattern = VA_.*(\\.(?i)(csv|dat))$
delete.after.download = false
[SMB]
; Access SMB target?
active = false
[SCP]
; Access SCP target?
active = false
[FTP_Accounts]
ftpAccount = /aaa/xxx
ftpAccount = /bbb/xxx
ftpAccount = /ccc/xxx
ftpAccount = /ddd/xxx
ftpAccount = /eee/xxx
ftpAccount = /fff/xxx
The follwoing Java code doesn't get me all options values for option key ftpAccount:
public SftpFileHandler() {
Wini ini = null;
try {
Config.getGlobal().setEscape(false);
Config.getGlobal().setMultiSection(true);
Config.getGlobal().setMultiOption(true);
ini = new Wini(new File("MyIniFile.ini"));
} catch (InvalidFileFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
final String ftpFileNamePattern =
ini.get("FTP", "file.pattern", String.class);
pattern = Pattern.compile(ftpFileNamePattern);
List<Ini.Section> list = ini.getAll("FTP_Accounts");
final Ini.Section ftpAccountsSection = ini.get("FTP_Accounts");
for (final String optionKey: ftpAccountsSection.keySet()) {
System.out.println(optionKey);
}
ftpAccounts = ftpAccountsSection.getAll("ftpAccount", String[].class);
final List<String> ftpAccountsList = ftpAccountsSection.getAll("ftpAccount");
final Ini.Section sftpAccountsSection = ini.get("SFTP_Accounts");
sftpAccounts = sftpAccountsSection.getAll("sftpAccount", String[].class);
connect();
}
I thought I could get all the option values with the getAll calls into an array.