导航:首页 > 编程语言 > 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如何生成产品序列号相关的资料

热点内容
win10更新后进不了剑灵 浏览:243
iphone471激活出错 浏览:648
怎么把文件拷到u盘 浏览:620
中伊签署文件视频 浏览:661
电信光宽带网络不稳定 浏览:504
网络岗软路由 浏览:995
黑莓z10在哪里下载app 浏览:310
net批量下载文件 浏览:696
怎么把苹果一体机文件拷贝 浏览:117
sql文件怎么写 浏览:9
帝豪ec718导航升级 浏览:257
如何运用编程进行统计 浏览:570
excel如何拉考勤数据 浏览:879
大智慧612手机版本 浏览:796
编程试什么 浏览:252
plc编程要遵循什么规则 浏览:16
苹果平板电脑a1476 浏览:221
创建mysql数据库的步骤 浏览:406
本地磁盘文件夹找不到了 浏览:590
怎么编辑win10的hosts文件 浏览:823

友情链接