-
Java: String 类对正则的支持
2020-12-16 15:41:45文章目录java.long.String 中的对正则的支持方法进行字符串验证, 匹配某个正则根据正则替换全部根据正则替换首个根据正则拆分根据正则拆分成指定的个数案例, 找出字符串中的字母案例: 字符串拆分(按数字拆分)案例: ...文章目录
java.long.String 中的对正则的支持方法
进行字符串验证, 匹配某个正则
public boolean matches(String regex)
根据正则替换全部
public String replaceAll(String regex, String replacement)
根据正则替换首个
public String replaceFirst(String regex, String replacement)
根据正则拆分
public String[] split(String regex)
根据正则拆分成指定的个数
public String[] split(String regex, int limit)
案例, 找出字符串中的字母
package com.cwq.beyond; public class test22 { public static void main(String[] args) { String str = "@#@#fdsafSJHFK&*(IDHFK^F(#@HJHKJsdfsafw213214KJHdsf*^#Jkh324jk2#@"; String regex = "[^a-zA-Z]"; System.out.println(str.replaceAll(regex, "")); } }
案例: 字符串拆分(按数字拆分)
package com.cwq.beyond; public class test22 { public static void main(String[] args) { String str = "aaaa980943bbbUUER89wer89Jjls"; String regex = "\\d+"; // 正则[0-9] String data[] = str.split(regex); for (int i = 0; i < data.length; i++) { System.out.println(data[i]); } } }
案例: 验证字符串是否是数字(包括整数和小数),如果是要变成Double型
package com.cwq.beyond; public class test22 { public static void main(String[] args) { String str = "11011"; String regex = "\\d+(\\.\\d+)?"; // (\\.\\d+)? 量词, 0 次或者 一次, ()表示一个整体 if (str.matches(regex)) { Double data = Double.parseDouble(str); System.out.println(data); } } }
案例: 判断一个字符串是否是日期类型, 是则转化成Date型
package com.cwq.beyond; import java.text.SimpleDateFormat; public class test22 { public static void main(String[] args) throws Exception{ String str = "2020-10-12 14:45:12"; String regex = "\\d{4}-\\d{2}-\\d{2}"; if (str.matches(regex)) { System.out.println(new SimpleDateFormat("yyyy-MM-dd").parse(str)); }else if (str.matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}")) { System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(str)); } } }
案例: 判断给定的电话号码格式是否正确
package com.cwq.beyond; import java.text.SimpleDateFormat; public class test22 { public static void main(String[] args) throws Exception{ /* * 电话格式1 : 12345678 * 电话格式2 : 01012345678 * 电话格式3 : (010)-12345678 */ String str[] = {"12345678","01012345678","(010)-12345678"}; String regex = "(\\()?(\\d{3,4})?(\\)-)?\\d{7,8}"; // 或者: (\\(\\d{3,4}\\)-|(\\d{3,4}))?\\d{7,8} for (int i = 0; i < str.length; i++) { if (str[i].matches(regex)) { System.out.println("格式正确"); }else { System.out.println("格式错误"); } } } }
-
java中使用正则对格式的验证
2014-12-31 23:52:48import java.util.regex.*; public final class RegExpValidator { public static boolean isEmail(String str) { String regex = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\...import java.util.regex.*;public final class RegExpValidator {public static boolean isEmail(String str) {
String regex = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
return match(regex, str);
}public static boolean isIP(String str) {
String regex = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b";
return match(regex, str);
}@Deprecated
public static boolean IsUrl(String str) {
str = str.toLowerCase();
//String regex = "^(http|www|ftp|https|)?(://)?(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*((:\\d+)?)(/(\\w+(-\\w+)*))*(\\.?(\\w)*)(\\?)?(((\\w*%)*(\\w*\\?)*(\\w*:)*(\\w*\\+)*(\\w*\\.)*(\\w*&)*(\\w*-)*(\\w*=)*(\\w*%)*(\\w*\\?)*(\\w*:)*(\\w*\\+)*(\\w*\\.)*(\\w*&)*(\\w*-)*(\\w*=)*)*(\\w*)*)$";
String regex = "^http://[\\w-\\.]+(?:/|(?:/[\\w\\.\\-]+)*(?:/[\\w\\.\\-]+\\.*))?$";
return match(regex, str);
}public static boolean isTelephone(String str) {
String regex = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
return match(regex, str);
}public static boolean isPostalcode(String str) {
String regex = "[1-9]\\d{5}(?!\\d)";
return match(regex, str);
}public static boolean isIDcard(String str) {
String regex = "(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])";
return match(regex, str);
}public static boolean isDate(String str) {
String regex = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$";
return match(regex, str);
}private static boolean match(String regex, String str) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
return matcher.matches();
}public static void main(String[] args) {
System.out.println(RegExpValidator.isEmail("448117419@qq.com"));
System.out.println(RegExpValidator.isIP("192.168.1.123"));
System.out.println(RegExpValidator.isDate("2012-10-10"));
System.out.println(RegExpValidator
.IsUrl("HTTP://www.baidu.nn/hello.do"));
System.out.println(RegExpValidator.isTelephone("13522349251"));
System.out.println(RegExpValidator.isPostalcode("417000"));
System.out.println(RegExpValidator.isIDcard("431221199110020817"));
}} -
java中String对正则表达式的支持
2015-01-12 14:02:21概念:以一个特殊的字符串来描述一个格式,让程序按照这个格式去验证字符串,那么用于描述格式的这个字符串就是正则表达式。正则表达是只规定格式,不规定内容。 验证一个字符串是否满足一个正则表达式的方法:...声明:以下纯属个人见解和总结,可能存在理解错误的地方,如有发现敬请指出,不胜感激。
概念:以一个特殊的字符串来描述一个格式,让程序按照这个格式去验证字符串,那么用于描述格式的这个字符串就是正则表达式。正则表达是只规定格式,不规定内容。
验证一个字符串是否满足一个正则表达式的方法:boolean str.matches(String regex);
正则表达式常用语法
1、" () "和" [] "的使用
// "()"表示把括号中的内容看作整体匹配 String regex1 = "(ABC)"; System.out.println("A".matches(regex1));// false System.out.println("ABC".matches(regex1));// true System.out.println("ABCDEFG".matches(regex1));// false System.out.println("ABCABC".matches(regex1));// false // "[]"表示匹配括号中的字符任选其一 String regex2 = "[ABC]"; System.out.println("A".matches(regex2));// true System.out.println("B".matches(regex2));// true System.out.println("C".matches(regex2));// true System.out.println("AB".matches(regex2));// false System.out.println("ABC".matches(regex2));//false System.out.println("ABCDEFG".matches(regex2));// false System.out.println("ABCABC".matches(regex2));// false
2、" ^ "的使用
在一些资料中," ^ "被介绍成"匹配输入字符串的开始位置"。
但是我在java代码中的使用过程和测试中发现:如果" ^ "不是出现在" [] " 中,没有实际的意义,当出现在" [] "中是表示"非"的意思。
String regex1 = "ABC"; System.out.println("A".matches(regex1));// false System.out.println("BC".matches(regex1));// false System.out.println("ABC".matches(regex1));// true System.out.println("ABCABC".matches(regex1));// false System.out.println("ABCDEFG".matches(regex1));// false System.out.println("DDD ABC".matches(regex1));// false // "^"在这里没有实际的意义,结果与上面相同 String regex2 = "^ABC"; System.out.println("A".matches(regex2));// false System.out.println("BC".matches(regex2));// false System.out.println("ABC".matches(regex2));// true System.out.println("ABCABC".matches(regex2));// false System.out.println("ABCDEFG".matches(regex2));// false System.out.println("DDD EFG".matches(regex2));// false // "^"在这里没有意义 String regex3 = "(^ABC)"; System.out.println("A".matches(regex3));// false System.out.println("BC".matches(regex3));// false System.out.println("ABC".matches(regex3));// true System.out.println("DBC".matches(regex3));// false System.out.println("EFG".matches(regex3));// false System.out.println("ABCDEFG".matches(regex3));// false // "^"在这里表示"非"的意思,表示除A,B,C意外的任意一个字符 String regex4 = "[^ABC]"; System.out.println("A".matches(regex4));// false System.out.println("B".matches(regex4));// false System.out.println("C".matches(regex4));// false System.out.println("BC".matches(regex4));// false System.out.println("ABC".matches(regex4));// false System.out.println("D".matches(regex4));// true System.out.println("E".matches(regex4));// true System.out.println("\n".matches(regex4));// true
3、" | "的使用
在上面的介绍中,我们知道" ^ "可以表示"非",同样我们还可以在正则表达式中使用" | "(或)。
" | "或使用示例:
String regex1 = "A|B|C"; System.out.println("".matches(regex1));// false System.out.println("A".matches(regex1));// true System.out.println("B".matches(regex1));// true System.out.println("C".matches(regex1));// true System.out.println("D".matches(regex1));// false System.out.println("AB".matches(regex1));// false String regex2 = "[ABC]|(DEF)"; System.out.println("".matches(regex2));// false System.out.println("A".matches(regex2));// true System.out.println("B".matches(regex2));// true System.out.println("C".matches(regex2));// true System.out.println("AB".matches(regex2));// false System.out.println("ABC".matches(regex2));// false System.out.println("D".matches(regex2));// false System.out.println("DEF".matches(regex2));// true System.out.println("ABCDEF".matches(regex2));// false
这时候有人可能会问" || "这个或行不行,在正则表达式中" || "可以使用,但是会被当作两个" | "使用,而且中间是一个长度为0的字符串。
String regex3 = "A||B||C"; // 注意,这时的"".matches(regex3)结果为true,而上面的例子中结果为false System.out.println("".matches(regex3));// true System.out.println("A".matches(regex3));// true System.out.println("B".matches(regex3));// true System.out.println("C".matches(regex3));// true System.out.println("D".matches(regex3));// false System.out.println("AB".matches(regex3));// false
4、正则表达式的区间表示
通过使用" [] "可以表示区间、范围,或者可以说是一个简写,具体通过如下的实例进行理解。
[a-z]:只能出现一个小写英文字母,a-z表示一项,只不过是一个范围。
[0-9]:只能出现一个数字。
[a-zA-Z0-9]:描述一个字符,可以是任意数字或字母。
[^0-9]:只能出现一个非数字的字符。
5、" && "的使用
在上面的内容中介绍了"或"和"非"的使用,有人会问,正则表达式中是否可以使用"与"。
答案是肯定的,但是"与"的使用比"或"和"非"比较难于理解,最简单的方法就是将" && "理解成为交集。
" && "使用示例:
// 任意一个小写字母的集合 与 任意一个非b、c字符的集合 的交集 // 即得到集合{a,d,e,f,g,h,i,j,kl,m,n,o,p,q,r,s,t,u,v,w,x,y,z} String regex1 = "[a-z&&[^bc]]"; System.out.println("----------" + regex1 + "----------"); System.out.println("a".matches(regex1));// true System.out.println("b".matches(regex1));// false System.out.println("d".matches(regex1));// true System.out.println("\n".matches(regex1));// false // 任意一个小写字母的集合 与 集合{d,e,f,A,B,C}的交集 // 即得到集合{d,e,f} String regex2 = "[a-z&&[defABC]]"; System.out.println("----------" + regex2 + "----------"); System.out.println("a".matches(regex2));// false System.out.println("d".matches(regex2));// true System.out.println("e".matches(regex2));// true System.out.println("f".matches(regex2));// true System.out.println("g".matches(regex2));// false System.out.println("A".matches(regex2));// false // 任意一个小写字母 与 任意一个数字 的交集 // 得到一个空集,所以任何字符串进行校验都是返回false String regex3 = "[a-z&&0-9]"; System.out.println("----------" + regex3 + "----------"); System.out.println("".matches(regex3));// false System.out.println("a".matches(regex3));// false System.out.println("0".matches(regex3));// false System.out.println("a&&0".matches(regex3));// false System.out.println("a-z&&0-9".matches(regex3));// false System.out.println("[a-z&&0-9]".matches(regex3));// false
" && "必须出现在" [] "中才有意义,否则就是普通的字符串"&&"。
// 这里"&&"并不是"与"的意思,而是表示字符&& String regex4 = "A&&B"; System.out.println("A&&B".matches(regex4));// true String regex5 = "(ABC)&&(DEF)"; System.out.println("ABC&&DEF".matches(regex5));// true String regex6 = "[ABC]&&[DEF]"; System.out.println("A&&D".matches(regex6));// true System.out.println("B&&D".matches(regex6));// true
6、正则表达式中的量词在正则表达式中常用的量词有如下几个:
?:表示前面的内容出现0-1次
*:表示前面的内容出现0-任意次
+:表示前面的内容出现1-任意次
{n}:表示前面的内容出现n次
{n,m}:表示出现最少n次,最多m次
{n,}:表示出现n次以上
使用示例:
// "?"表示前面的内容出现0-1次 String regex1 = "A?"; System.out.println("".matches(regex1));// true System.out.println("A".matches(regex1));// true System.out.println("AA".matches(regex1));// false System.out.println("AB".matches(regex1));// false System.out.println("B".matches(regex1));// false // "*"表示前面的内容出现0-任意次 String regex2 = "A*"; System.out.println("".matches(regex2));// true System.out.println("A".matches(regex2));// true System.out.println("AA".matches(regex2));// true System.out.println("AB".matches(regex2));// false System.out.println("B".matches(regex2));// false // "+"表示前面的内容出现1-任意次 String regex3 = "A+"; System.out.println("".matches(regex3));// false System.out.println("A".matches(regex3));// true System.out.println("AA".matches(regex3));// true System.out.println("AB".matches(regex3));// false System.out.println("B".matches(regex3));// false // "{n}"表示前面的内容出现n次 String regex4 = "A{2}"; System.out.println("".matches(regex4));// false System.out.println("A".matches(regex4));// false System.out.println("AA".matches(regex4));// true System.out.println("AAA".matches(regex4));// false System.out.println("BAA".matches(regex4));// false // "{n,m}"表示出现最少n次,最多m次 String regex5 = "A{2,4}"; System.out.println("A".matches(regex5));// false System.out.println("AA".matches(regex5));// true System.out.println("AAA".matches(regex5));// true System.out.println("AAAA".matches(regex5));// true System.out.println("AAAAA".matches(regex5));// false System.out.println("AAB".matches(regex5));// false // "{n,}"表示出现n次以上 String regex6 = "A{2,}"; System.out.println("A".matches(regex6));// false System.out.println("AA".matches(regex6));// true System.out.println("AAA".matches(regex6));// true System.out.println("AAAA".matches(regex6));// true System.out.println("AAAAA".matches(regex6));// true System.out.println("BAA".matches(regex6));// false
7、正则表达式中常用的元字符
其实在上面介绍的" ^ "," | "," () "," [] "," ? "," * "," + "," {} "都是正则表达式中的元字符。这里再介绍一些常用的元字符。
.:用来描述除了"\n"之外的任意一个字符
\d:描述任意一个数字,等同于[0-9]
\D:描述任意一个非数字字符,等同[^0-9],[^\d]
\s:任意一个空白字符,例如空格,\t,\n等
\S:描述任意一个非空白字符
\w:任意一个单词字符,等同[a-zA-Z_0-9]
\W:任意一个非单词字符,等同[^\w]
注意:由于元字符在正则表达式中有特殊的含义,java编译器在编译是会将第一个"\"作为转义字符,所以我们在使用带有"\"的元字符时,需要使用"\\"。
使用示例:
String regex1 = "."; System.out.println("A".matches(regex1));// true System.out.println("\t".matches(regex1));// true System.out.println("\b".matches(regex1));// true System.out.println("\n".matches(regex1));// false System.out.println("a".matches(regex1));// true System.out.println(".".matches(regex1));// true String regex2 = "\\d"; System.out.println("A".matches(regex2));// false System.out.println("0".matches(regex2));// true String regex3 = "\\D"; System.out.println("A".matches(regex3));// true System.out.println("0".matches(regex3));// false System.out.println("\n".matches(regex3));// true String regex4 = "\\s"; // 这是一个空格 System.out.println(" ".matches(regex4));// true System.out.println("\t".matches(regex4));// true System.out.println("\n".matches(regex4));// true System.out.println("A".matches(regex4));// false String regex5 = "\\S"; System.out.println(" ".matches(regex5));// false System.out.println("\t".matches(regex5));// false System.out.println("A".matches(regex5));// true System.out.println(".".matches(regex5));// true String regex6 = "\\w"; System.out.println("A".matches(regex6));// true System.out.println("a".matches(regex6));// true System.out.println("0".matches(regex6));// true System.out.println("_".matches(regex6));// true System.out.println(".".matches(regex6));// false String regex7 = "\\W"; System.out.println("A".matches(regex7));// false System.out.println("a".matches(regex7));// false System.out.println("0".matches(regex7));// false System.out.println("_".matches(regex7));// false System.out.println(".".matches(regex7));// true System.out.println("\n".matches(regex7));// true
如果在正则表达式中需要匹配" ^ "," ? "," * "," + "," () "," [] "," . "等元字符,我们需要使用"\"进行转义。由于java编译器在编译时会将第一个"\"作为转义字符转义,所以我们需要使用"\\"。
// String regex1 = "\^";// 编译错误 String regex1 = "\\^"; System.out.println("^".matches(regex1));// true String regex2 = "\\(\\)"; System.out.println("()".matches(regex2));// true String regex3 = "\\."; System.out.println(".".matches(regex3));// true String regex4 = "\\{\\}"; System.out.println("{}".matches(regex4));// true
8、在正则表达式中可以使用Unicode字符例如:
// 判断一个字符串是否全是中文 String regex = "[\u4e00-\u9fa5]*"; System.out.println("ABC".matches(regex));// false System.out.println("ABC中文".matches(regex));// false System.out.println("中文ABC".matches(regex));// false System.out.println("ABC中文DEF".matches(regex));// false System.out.println("中文".matches(regex));// true
9、正则表达式中还可以使用ASCII编码
// 十六进制表示法,必须为确定的两个数字长 String regex1 = "\\x41"; System.out.println("A".matches(regex1));// true // 八进制表示法 String regex2 = "\\0101"; System.out.println("A".matches(regex2));// true String regex3 = "\\x61"; System.out.println("a".matches(regex3));// true String regex4 = "\\0141"; System.out.println("a".matches(regex4));// true
-
java通过正则表达式验证uuid的格式
2020-10-31 16:54:23有时候后端需要对指定的入参进行格式验证,判断入参是否是我们想要的uuid格式的数据,将错误格式数据排查在外. 最早应用的代码 public static boolean checkUuid(String uuid){ boolean isUuid = false; if (uuid....应用场景
有时候后端需要对指定的入参进行格式验证,判断入参是否是我们想要的uuid格式的数据,将错误格式数据排查在外.
最早应用的代码
public static boolean checkUuid(String uuid){ boolean isUuid = false; if (uuid.matches("(\\w{8}(-\\w{4}){3}-\\w{12}?)")) return true; return isUuid; }
结果
结果就很尴尬,只要位数符合要求就可以通过验证,没有达到预期的目的,所以有了下面的代码.升级版
public static boolean checkUuidV2(String uuid){ boolean isUuid = false; if (uuid.matches("([0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}?)")) return true; return isUuid; }
这次的结果就是达到了个人预期了
-
正则表达式(java电话号码,邮箱格式验证)
2020-07-27 18:35:52String s1 ="i love java"; boolean b = s1.matches("^i\\s\\w{4}\\s\\w{3}a$");//其中^位开头,$为结尾,主义的是一定要写开头和结尾字符 System.out.println(b); 在我国电话格式这么写:String reg = “1... -
java注解验证实体_Java通过注解和反射 实现模拟 Hibernate Validator验证框架对实体对象的字段验证功能...
2021-03-11 15:06:07需求:1实现对字段的非空校验2实现对邮箱的正则验证3实现对年龄字段的未成年判断输出:若字段为空则打印注解传递的message若邮箱格式正则验证不通过则输出邮箱格式错误若年龄小于18则打印注解传递的message1 创建一... -
Java 通过注解和反射 实现模拟 Hibernate Validator验证框架对实体对象的字段验证功能
2020-07-06 20:40:282实现对邮箱的正则验证 3实现对年龄字段的未成年判断 输出: 若字段为空则打印注解传递的message 若邮箱格式正则验证不通过则输出邮箱格式错误 若年龄小于18则打印注解传递的message 1 创建一个实体类... -
java excel 导入手机号码(包括对手机的验证)
2012-08-16 11:25:14* 此代码是完成从excel导入电话号码,将正确的电话号码保存到set集合中,因为set集合对于重复的值会覆盖,所以达到了去重复的值的用例,并累计了不正确的电话号码的个数,对电话号码进行了验证有效性。所需要的 dom4... -
java rsa 公钥格式_Java 从文件加载RSA公钥
2021-02-12 22:12:56openssl genrsa [-out file] –des3在此之后,我生成了一个公共密钥:openssl rsa –pubout -in private.key [-out file]我想使用私钥对某些消息进行签名,并使用诸如此类的代码对其他私钥进行验证:public String ... -
表达式语言之java对正则表达式的处理
2016-04-09 07:58:00例如注册email格式的验证等。java中处理正则表达式相关的类主要有java.lang.String,java.util.regex.Pattern,java.util.regex.Matcher等。 java.util.regex.Pattern在JDK中的定义为:指定为字符串的正则表达式必须... -
一些我经过验证的-有效的-【正则表达式】-JAVA
2018-01-20 09:59:20在开发中,我们经常需要对参数做验证。需要用到一些正则表达式。这里我整理写我验证过的 正则表达式。 一: /** * shang * 判断email格式是否正确 */ public static boolean isEmail(String email) { String ... -
对Java虚拟机(JVM)的理解
2021-03-28 11:45:40验证:验证文件格式、元数据、字节码、符号引用 准备:为类的静态变量分配内存 并将其初始化为默认值。基本类型初始化为0 String类型初始化默认为null 解析:将类中的符号引用转变为直接引用 初始化:将类的静态变量... -
java 整数转化为时间_JAVA实现日期+整数转换为日期的类
2021-03-01 06:07:52import java.text.ParseException;import java.text.SimpleDateFormat;.../*** 该类主要完成对字符的验证和过滤* @author**/public class StringUtil {//转换日期格式public static java.sql.Date parseDate(S... -
java源码包---java 源码 大量 实例
2013-04-18 23:15:26Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码,... -
Java基础--31--Java安全编码规范
2020-12-10 17:07:06程序接受数据可能来源于未经验证的用户,网络连接和其他不受信任的来源,如果未对程序接受数据进行校验,则可能会引发安全问题。 1.1、避免SQL注入 使用PreparedStatement预编译SQL,解决SQL注入问题,传递给... -
java中正则表达式最基本的使用
2019-07-28 21:26:13正则表达式是一种最早起源于Perl语言的特殊字符串技术,可以通过一些固定的模式编写一些特殊的字符串,通过对这些特殊字符串使用,可以有效的进行表单验证(手机,邮箱,网址等输入格式的检查),以及一些数据的爬取,... -
java源码包2
2013-04-20 11:28:17Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码... -
JAVA实现日期+整数转换为日期的类
2012-08-03 13:40:00<pre class="java" name="code">import java.text.ParseException;import java.text.SimpleDateFormat;.../*** 该类主要完成对字符的验证和过滤* @author* */public class StringUtil {//转换日期格式... -
日期的有效验证
2018-04-05 14:03:55并通过做上机任务5加深了对一些常用方法的了解以及如何对其怎样使用,其中有一道题如下:从控制台输入一个日期,要求必须以09/30(月/日)的格式输入。import java.util.Scanner;public class Date { public static ... -
-
java源码包3
2013-04-20 11:30:13Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码... -
java源码包4
2013-04-20 11:31:44Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码... -
JSP中多用户名格式的重复确认及报错
2019-10-05 11:50:42本次的博客主要讲述对用户名的格式的验证及报错,以下的代码为JSP页面代码,在下面的代码中有三次输入,并且每次的输入都遵循同一种规则,即输入的字符只能为1~9,a~z,A~Z这三种范围的字符,并且长度最短不能为0,... -
java文件读取
2018-04-13 12:24:58最近在用java对文件读取,进行访问验证,最后编写如下 读取的格式 private static String pathname = "/usr/local/apache-tomcat-9.0.6/webapps/test4_Admin.txt";File Admin=new File(pathname);InputStreamReader ... -
为什么JAVA中一些类用另的一个类的对象来调用?
2018-05-10 13:35:00设计模式:对问题行之有效的解决方式.其实它是一种思想. 1.单例设计模式. 解决的问题:就是可以保证一个类在内存中的对象唯一性. 必须对于多个程序使用同一个配置信息对象时,就需要保证该对象的唯一性. 如何保证... -
深入Java虚拟机
2014-06-28 23:53:103.4.4 第四趟:符号引用的验证 3.4.5 二进制兼容 3.5 Java虚拟机中内置的安全特性 3.6 安全管理器和Java API 3.7 代码签名和认证 3.8 一个代码签名示例 3.9 策略 3.10 保护域 3.11 访问控制器 ... -
java面试宝典
2013-02-28 16:04:0141、Java 的接口和C++的虚类的相同和不同处。 12 42、一个“.java”源文件中是否可以包含多个类(不是内部类)?有什么限制? 12 43、说出一些常用的类,包,接口,请各举5 个。 12 44、Anonymous Inner Class (匿名... -
JAVA 正则表达式
2010-01-15 11:16:37由于工作的需要,本人经常要面对大量的文字电子资料的整理工作,因此曾对在 JAVA 中正则表达式的应 用有所关注,并对其有一定的了解,希望通过本文与同行进行有关方面的心得交流。 正则表达式: 正则表达式是一... -
Java学习笔记-个人整理的
2012-12-19 09:57:07{1.14.1}Java的打包命令}{44}{subsection.1.14.1} {2}Everything is an Object }{45}{chapter.2} {2.1}类与对象}{45}{section.2.1} {2.1.1}构造方法}{45}{subsection.2.1.1} {2.1.2}Java变量类型}{47}{... -
JAVA上百实例源码以及开源项目
2016-01-03 17:37:40Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码,...