[英]How i can get max value of this increment?
I have increment syntax, and i want to save the last maximum value , so when i close my program and open it again , the increment will start from the last maximum value not start from 0 again .. but here my syntax always start from 0 again, so what to do ? 我有增量语法,我想保存最后一个最大值,所以当我关闭程序并再次打开它时,增量将从最后一个最大值开始,而不是从0开始..但这里我的语法总是从0开始再次,该怎么办?
private long l = 100000;
view.getRdbtnUmum().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(view.getRdbtnUmum().isSelected() == true){
view.getRdbtnPrestone().setSelected(false);
view.getTxtJobCode().setValue("JU" + l);
}
l++;
model.setjPres(l);
}
});
You need to persist the last value somewhere. 您需要将最后一个值保留在某个地方。 You can simply choose to write it on a simple file or you can persist it in a DB. 您可以选择将其写入简单文件中,也可以将其持久保存在数据库中。
If you can use the last maximum value, you can save the value to the file or database. 如果可以使用最后一个最大值,则可以将该值保存到文件或数据库中。
To save the value into file: 要将值保存到文件中:
public static void serializeSumNum(int sum){
ObjectOutputStream oos = null;
try{
FileOutputStream fout = new FileOutputStream("D:\\sum\\sum.txt");
oos = new ObjectOutputStream(fout);
oos.writeObject(sum);
System.out.println("Done");
}catch(Exception ex){
ex.printStackTrace();
}
finally {
//Close the ObjectOutputStream
try {
if (oos != null) {
oos .flush();
oos .close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.