元振java增加版本号_Java如何⽣成版本号?⽐如000100020002展开全部
⾸先还是不太明⽩你说的这636f70793231313335323631343130323136353331333431373261个“⽣成版本号”是什么意思,如果只是⽣成⼀个⾃增序列的话
1、如果有oracle数据库的话可以利⽤它的序列⽣成。
2、没有oracle,⽤redis也⾏。
3、没有数据库,那就写个⽂件来存取吧:
public class Test2 {
public static void main(String[] args) throws IOException {
System.out.println(getSequence("d:\\test\\"));
tSequence("d:\\test\\", "");
System.out.println(getSequence("d:\\test\\"));
}
//读取序列
public static String getSequence(String quenceFile) throws IOException {
FileInputStream fileInputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
try {
File file = new File(quenceFile);
fileInputStream = new FileInputStream(file);大岩山
inputStreamReader = new InputStreamReader(fileInputStream);
bufferedReader = new BufferedReader(inputStreamReader);
// 按⾏读取字符串
String str;
if ((str = adLine()) != null) {
return str;
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (bufferedReader != null) {
描写初春的优美句子bufferedReader.clo();
}
if (inputStreamReader != null) {
沉思的意思inputStreamReader.clo();
}
if (fileInputStream != null) {
读书手抄报二年级
fileInputStream.clo();
}
}
}
//设置序列,如果传⼊的序列号为空,则在原序列的基础上+1
public static void tSequence(String quenceFile, String quence) throws IOException { if (quence == null || quence.isEmpty()) {
String oriSequence = getSequence(quenceFile);
quence = String.format("%04d", Integer.valueOf(oriSequence) + 1);
}
FileOutputStream fileOutputStream = null;
宿舍关系OutputStreamWriter outputStreamWriter = null;
BufferedWriter bufferedWriter = null;
try {
File file = new File(quenceFile);
fileOutputStream = new FileOutputStream(file);
outputStreamWriter = new OutputStreamWriter(fileOutputStream);
bufferedWriter = new BufferedWriter(outputStreamWriter);
bufferedWriter.write(quence);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bufferedWriter != null) {
bufferedWriter.clo();
}
赞美家乡的句子if (outputStreamWriter != null) {
outputStreamWriter.clo();
}
if (fileOutputStream != null) { fileOutputStream.clo();
}
}
}
}
代码⼜挤在⼀起了:
读序列:
写序列:
运⾏结果:
先⽣成好这个⽂件:
合欢花开
冲!: