I would like to use this method to convert a 2D Array to string into a properties file. Then, import it from the properties by converting the properties string back to a 2D Array. But I have difficulties with converting the String back to a 2D array.
EDIT: I want to reverse the 2D array string output back to 2D array. But the question you gave me doesn't help me with the 2D array one. As the Arrays.replace() can't replace the 2D array's internal one.
Here's my code:
public static void getSettings(){
try {
File file = new File("config.properties");
Properties p = new Properties();
FileInputStream fileInput = new FileInputStream(file);
//Import
moduleNames = p.getProperty("moduleNames").split("");
moduleData = ??? //I don't know how to convert String to String[][]
}
catch (Exception e){
e.printStackTrace();
}
}
Here's the another function to set property:
public static void writeFile(String[][] mD, String[] mN){
try{
Properties p = new Properties;
File file = new File("config.properties");
p.setProperty("moduleData", Arrays.deepToString("mD"));
p.setProperty("moduleNames", Arrays.toString("mN"));
//...further more code to flush the data out
} catch (Exception e){
e.printStackTrace();
}
}
Can anyone tell me how to convert String (from deepToString) back to String[][]?
My project is in Open source. This: Conf.java Line271 is the set properties one.
And this: Conf.java Line215 is the load String to String[][] one.