验证邮箱
public static boolean isEmail(String email) {
if (email == null || "".equals(email)) return false;
String regex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
return email.matches(regex);
}
验证电话
public static boolean isPhoneNumber(String phoneNumber) {
if (phoneNumber == null || "".equals(phoneNumber))
return false;
String regex = "^1[3|4|5|8][0-9]\\d{8}$";
return phoneNumber.matches(regex);
}
图片转字节数组
public byte[] img2byteArray(String path) {
try (FileImageInputStream input = new FileImageInputStream(new File(path));
ByteArrayOutputStream output = new ByteArrayOutputStream();) {
byte[] buf = new byte[1024];
int numBytesRead = 0;
while ((numBytesRead = input.read(buf)) != -1) {
output.write(buf, 0, numBytesRead);
}
return output.toByteArray();
} catch (IOException ex1) {
ex1.printStackTrace();
}
return null;
}
字节数组转图片
public void byteArray2img(byte[] data, String path) {
if (data.length < 3 || path.equals("")) {
return;
}
try (FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));) {
imageOutput.write(data, 0, data.length);
} catch (Exception ex) {
System.out.println("Exception: " + ex);
ex.printStackTrace();
}
}