導航:首頁 > 編程語言 > java如何生成產品序列號

java如何生成產品序列號

發布時間:2023-07-11 05:57:33

A. 求java自動生成一個序列號的方法,急急急...

package com.test4;

public class Test7 {
public static void main(String[] args) {
System.out.println(getNum("20100505",3));
}

//假設資料庫里有個20100505005的編號
private static String getNum(String firstPart, int len) {
//調用資料庫獲內得20100505005這個容編號
String oldNum = "20100505005";
int num = Integer.parseInt(oldNum.replace(firstPart,""));
String numStr = ++num +"";
int length = numStr.length();
for (int i = length; i < len; i++) {
numStr = "0"+numStr;
}
return firstPart + numStr;
}
}

B. 跪求在JAVA里如何獲得CPU的序列號,和硬碟的序列號。

利用Runtime call操作系統的命令,具體的命令取決於不同的操作系統,注意不要調用Runtime.getRuntime().exec(String)介面,要用Runtime.getRuntime().exec(String[])這個介面,不然復雜命令的執行會有問題。例子如下(拿cpu個數,其他類似):
定義命令:
WindowsCmd ="cmd.exe /c echo %NUMBER_OF_PROCESSORS%";//windows的特殊
SolarisCmd = {"/bin/sh", "-c", "/usr/sbin/psrinfo | wc -l"};
AIXCmd = {"/bin/sh", "-c", "/usr/sbin/lsdev -Cc processor | wc -l"};
HPUXCmd = {"/bin/sh", "-c", "echo \"map\" | /usr/sbin/cstm | grep CPU | wc -l "};
LinuxCmd = {"/bin/sh", "-c", "cat /proc/cpuinfo | grep ^process | wc -l"};

然後判斷系統:
os = System.getProperty("os.name").toLowerCase();

根據不同的操作系統call不同的命令。
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class GetMACAddress
{
public String getMACAddress(String ipAddress)
{
String str = "",strMAC = "",macAddress = "";
try
{
Process pp = Runtime.getRuntime().exec("nbtstat -a " + ipAddress);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for(int i = 1;i < 100;i++)
{
str = input.readLine();
if(str != null)
{
if(str.indexOf("MAC Address") > 1)
{
strMAC = str.substring(str.indexOf("MAC Address") + 14,str.length());
break;
}
}
}
}
catch(IOException ex)
{
return "Can't Get MAC Address!";
}
//
if(strMAC.length() < 17)
{
return "Error!";
}
macAddress = strMAC.substring(0,2) + ":"
+ strMAC.substring(3,5) + ":"
+ strMAC.substring(6,8) + ":"
+ strMAC.substring(9,11) + ":"
+ strMAC.substring(12,14) + ":"
+ strMAC.substring(15,17);
//
return macAddress;
}

public static void main(String[] args)
{
GetMACAddress getMACAddress = new GetMACAddress();
System.out.println(getMACAddress.getMACAddress("172.18.8.225"));

try
{
java.lang.Process proc = Runtime.getRuntime().exec("ipconfig /all");
InputStream istr = proc.getInputStream();
byte[] data = new byte[1024];
istr.read(data);
String netdata = new String(data);
System.out.println("Your Mac Address=" + procAll(netdata));
}
catch(IOException e)
{
System.out.println("error=" + e);
}
}

public static String procAll(String str)
{
return procStringEnd(procFirstMac(procAddress(str)));
}

public static String procAddress(String str)
{
int indexof = str.indexOf("Physical Address");
if(indexof > 0)
{
return str.substring(indexof,str.length());
}
return str;
}

public static String procFirstMac(String str)
{
int indexof = str.indexOf(":");
if(indexof > 0)
{
return str.substring(indexof + 1,str.length()).trim();
}
return str;
}

public static String procStringEnd(String str)
{
int indexof = str.indexOf("\r");
if(indexof > 0)
{
return str.substring(0,indexof).trim();
}
return str;
}
}

import java.util.Vector;

class GetNetMAC
{
//網卡物理地址長度
static private final int _physicalLength = 16;

public static void main(String[] args)
{
//output you computer phycail ip address
System.out.println("The MAC Addressis:\t" + getPhysicalAddress());
}

static public String getPhysicalAddress()
{
GetNetMACShell shell = new GetNetMACShell();
String cmd = "cmd.exe /c ipconfig/all";
Vector result;
result = shell.execute(cmd);
return parseCmd(result.toString());
}

//從字元串中解析出所需要獲得的字元串
static private String parseCmd(String s)
{
String find = "Physical Address. . . . . . . . . :";
int findIndex = s.indexOf(find);
if(findIndex == -1)
{
return "not find";
}
else
{
return s.substring(findIndex + find.length() + 1,findIndex + find.length() + 1 + _physicalLength);
}
}
}

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.util.Vector;

public class GetNetMACShell
{
private Process process = null;

public Vector execute(String shellCommand)
{
try
{
Start(shellCommand);
Vector vResult = new Vector();
DataInputStream in = new DataInputStream(process.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));

String line;
do
{
line = reader.readLine();
if(line == null)
{
break;
}
else
{
vResult.addElement(line);
}
}
while(true);
reader.close();
return vResult;

}
catch(Exception e)
{
//error
return null;
}
}

public void Start(String shellCommand)
{
try
{
if(process != null)
{
kill();
}
Runtime sys = Runtime.getRuntime();
process = sys.exec(shellCommand);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}

public void kill()
{
if(process != null)
{
process.destroy();
process = null;
}
}
}

試試是否可以:)

C. 如何用JAVA生成注冊序列號

平常我們都接觸過軟體注冊,輸入序列號、激活碼、注冊碼、授權碼;對於這些字元碼到底代表什麼含義不甚了解,但一般來說,這些字元碼中都有幾個特點:
1、唯一性,肯定是一個唯一的序列號,否則就會存在濫用的問題。
2、加密性,肯定是經過加密或者混亂的,防止大家自己生成序列號。
3、解密性,軟體自身肯定可以解密,否則無法驗證合法性。
4、可讀性,序列號一般都比較標准,方便書寫和記憶,所以一般都為數字和字母。
以下給出簡單示例:
[java] view plain
/**
* byte轉哈希
* @param b
* @return
*/
public static String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = Integer.toHexString(b[n] & 0xFF);
if (stmp.length() == 1)
hs += ("0" + stmp);
else
hs += stmp;
}
return hs.toUpperCase();
}

/**
* 哈希轉byte
* @param b
* @return
*/
public static byte[] hex2byte(byte[] b) {
if ((b.length % 2) != 0)
throw new IllegalArgumentException("長度不是偶數");

byte[] b2 = new byte[b.length / 2];

for (int n = 0; n < b.length; n += 2) {
String item = new String(b, n, 2);
b2[n / 2] = (byte) Integer.parseInt(item, 16);
}
return b2;
}

D. java自動生成進貨編碼

import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 自動生產編號
* @author
*chengeng
*/
public class AutoNum {
/**
*
* 在用此類時,必須先明確自己模塊編號的開頭
* @param start編號開頭,
* @param num從資料庫查詢出的最大編號
* @return
*/
public String getNum(String start,String num){
String n=num.substring(0,3);
if(!n.equals(start)){
System.out.println("編號的開頭與從資料庫取得的編號開頭不相同");
return "";
}
String strDate="";//流水號時間
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
//格式化當前時間,並按字元'-'分割
String[] sd=sdf.format(date).split("-");
//截取編號中的日期
String time=num.substring(3,11).toString();

for(int i=0;i<sd.length;i++){
strDate+=sd[i];
}
//如果當天或者表中沒有記錄,返回當天第一條記錄
if(!time.equals(strDate)||num.equals("")){
return start+strDate+"0001";
}
// 截取編號最後的流水號
String end=num.substring(11, 15);
String s2="";
int lg=Integer.parseInt(end);
//對流水號結尾的四位數字進行判斷,以便增加
if(lg>0&&lg<9){
s2="000"+(lg+1);
}else if(lg>=9&&lg<99){
s2="00"+(lg+1);
}else if(lg>=99&&lg<999){
s2="0"+(lg+1);
}else if(lg>=999&&lg<9999){
s2=""+(lg+1);
}
//返回自動生成後的流水號
return start+=strDate+s2;
}
}

E. java自動生成編號

private static int m=1;//全局靜態變數,(必須static修飾)每調用一次方法自增
public String add(){
addin(m);
return "addTiao";

}
public void addin(int a){
String str1="A";
Date date=new Date();
String str2=new SimpleDateFormat("yyyyMMdd"). format(date);//自動生成日期
int datee=Integer.parseInt(str2);
inlist=instockService.getInListDown();//按降冪排序
instockEntity=(InstockEntity) inlist.get(0);
String ss=instockEntity.getInstock_number();//得到最大日期
if(ss!=null){
String riqi=ss.substring(1, 9);
int riqi1=Integer.parseInt(riqi);
if(datee>riqi1){
a=1;//如果日期變大則初始化訂單號
}
}

String str3=null;
if(a>=0&&a<=9){
str3="00"+String.valueOf(a);
}else if(a>=10&&a<=99){
str3="0"+String.valueOf(a);
}else if(a>=100&&a<=999){
str3=String.valueOf(a);
}
String instock_number=str1+str2+str3;
instockEntity.setInstock_number(instock_number);

instockService.add(instockEntity);
m=a+1;
}

F. 怎樣生成 java 序列化id

你好:這個的話,可以這么搞

/**
*生成系統流水號
*@return流水號字元
*/
publicstaticStringgenerateNo(){

//接收流水號
StringgenerId="";

//生成5位隨機數
intradomInt=newRandom().nextInt(99999);

//獲取系統當前時間
StringdateInfo=DateUtil.getSysDate("yyMMddHHmm");

//當前系統時分秒加上五位隨機數,生成流水號
generId=dateInfo+String.valueOf(radomInt);
returngenerId;
}
閱讀全文

與java如何生成產品序列號相關的資料

熱點內容
網路評選一般有哪些 瀏覽:476
2021三支一扶報名數據在哪裡看 瀏覽:914
網路未備案怎麼打得開 瀏覽:987
計算機程序用什麼編程語言 瀏覽:324
linux入門常用命令 瀏覽:497
江寧區哪裡有數控編程培訓 瀏覽:778
java寫一個shape形狀類 瀏覽:744
win7如何設置word背景顏色 瀏覽:484
如何創造電腦編程語言 瀏覽:56
昂達平板電腦圖形密碼忘記怎麼辦 瀏覽:92
組織文件內容是什麼 瀏覽:183
0基礎如何學習智能編程 瀏覽:366
java程序員全攻略下載 瀏覽:715
網路逆向教程 瀏覽:135
iso文件如何重裝系統 瀏覽:750
ghost鏡像文件路徑如何恢復 瀏覽:832
搭建網站需要多少錢啊 瀏覽:599
編程貓怎麼設置背景亮度 瀏覽:177
qq文件破損 瀏覽:414
javapoi配置 瀏覽:608

友情鏈接