private File configurationFile;
public NewFile(File file){
this.configurationFile = file;
}
public void newFile() throws IOException{
if (!configurationFile.exists())
configurationFile.createNewFile();
}
< H2 > Configuration.java < / H2 >
private File configurationFile;
private Properties pro;
private FileInputStream input;
private FileOutputStream output;
int count = 0;
public Configuration(File configurationFile, Properties pro, FileInputStream input, FileOutputStream output){
this.configurationFile = configurationFile;
this.pro = pro;
this.input = input;
this.output = output;
}
public void write() throws IOException{
pro.load(input);
String value = pro.getProperty("name");
if (value != null){
count = Integer.parseInt(value);
}
countPP;
pro.setProperty("name", count + "");
pro.store(output, "");
input.close();
output.close();
}
< H2 > Main.java < / H2 >
public static void main(String[] args){
Configuration config = null;
File configFile = null;
FileInputStream input = null;
FileOutputStream output = null;
Properties pro = null;
NewFile newFile = null;
try{
configFile = new File("info.ini");
newFile = new NewFile(configFile);
newFile.newFile();
input = new FileInputStream(configFile);
output = new FileOutputStream(configFile);
pro = new Properties();
config = new Configuration(configFile, pro, input, output);
config.write();
}catch(IOException e){
e.printStackTrace();
}finally{
if(input != null){
try{
input.close();
}catch(IOException e){
e.printStackTrace();
}
}
if (output != null){
try{
output.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
I tested the code and found
if (value != null){
count = Integer.parseInt(value);
}
did not execute, but do not know why, solve