package com.util;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SuperUitl {
public static void main(String[] args) {
System.out.println();
}
/**
* 全角转半角
* trr 要转换成半角的字符串
*/
public static String change(String str) {
String outStr="";
String test="";
byte[] code = null;
for(int i=0;i<str.length();i++) {
try {
test = str.substring(i,i+1);
code = test.getBytes("unicode");
} catch(java.io.UnsupportedEncodingException e) {
}
if (code[3] == -1) {
code[2] = (byte)(code[2]+32);
code[3] = 0;
try {
outStr = outStr + new String(code,"unicode");
} catch(java.io.UnsupportedEncodingException e) {
}
} else {
outStr = outStr + test;
}
}
return outStr;
}
/**
* 根据key读取value
* filePath 要操作的properties文件路径
* key 要获得数据的key
*/
public static String readValue(String filePath,String key) {
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
String value = props.getProperty (key);
return value;
} catch (Exception e) {
return null;
}
}
/**
* 读取properties的全部信息
* filePath 要操作的properties文件路径
*/
public static Map readProperties(String filePath) {
Map map = new HashMap();
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String Property = props.getProperty (key);
map.put(key,Property);
}
return map;
} catch (Exception e) {
return null;
}
}
/**
* 写入properties信息
* filePath 要操作的properties文件路径
* key 要写入的key
* value 要写入的value
*/
public static boolean writeProperties(String filePath,String key,String value) {
Properties prop = new Properties();
try {
InputStream fis = new FileInputStream(filePath);
//从输入流中读取属性列表(键和元素对)
prop.load(fis);
//调用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
//强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。
OutputStream fos = new FileOutputStream(filePath);
prop.setProperty(key,value);
//以适合使用 load 方法加载到 Properties 表中的格式,
//将此 Properties 表中的属性列表(键和元素对)写入输出流
prop.store(fos, "Update '" + key + "' value");
return true;
} catch (IOException e) {
return false;
}
}
/**
* 返回标准系统时间
*/
public static String getDate() {
SimpleDateFormat ft=null;
Date date=null;
Calendar cl= Calendar.getInstance();
cl.setTime(new java.util.Date());
date=cl.getTime();
ft=new SimpleDateFormat("yyyy-MM-dd HH:mm");
String dateTime = ft.format(date);
return dateTime;
}
/**
* 从指定的字符串中提取Email
* content 指定的字符串
*/
public static String parse(String content) {
String email = null;
if (content==null || content.length()<1) {
return email;
}
//找出含有@
int beginPos;
int i;
String token = "@";
String preHalf="";
String sufHalf = "";
beginPos = content.indexOf(token);
if (beginPos>-1) {
//前项扫描
String s = null;
i= beginPos;
while(i>0) {
s = content.substring(i-1,i);
if (isLetter(s))
preHalf = s+preHalf;
else
break;
i--;
}
//后项扫描
i= beginPos+1;
while( i<content.length()) {
s = content.substring(i,i+1);
if (isLetter(s))
sufHalf = sufHalf +s;
else
break;
i++;
}
//判断合法性
email = preHalf + "@" + sufHalf;
if (isEmail(email)) {
return email;
}
}
return null;
}
/**
* 判断是不是合法Email
* email Email地址
*/
public static boolean isEmail(String email) {
try {
if (email==null || email.length()<1 || email.length()>256) {
return false;
}
String check = "^([0-9a-zA-Z]+[_.0-9a-zA-Z-]+)@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2,3})$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(email);
boolean isMatched = matcher.matches();
if(isMatched) {
return true;
} else {
return false;
}
} catch (RuntimeException e) {
return false;
}
}
/**
* 判断是不是合法字符
* c 要判断的字符
*/
public static boolean isLetter(String c) {
boolean result = false;
if (c==null || c.length()<0) {
return false;
}
//a-z
if (c.compareToIgnoreCase("a")>=0 && c.compareToIgnoreCase("z")<=0) {
return true;
}
//0-9
if (c.compareToIgnoreCase("0")>=0 && c.compareToIgnoreCase("9")<=0) {
return true;
}
//. - _
if (c.equals(".") || c.equals("-") || c.equals("_") ) {
return true;
}
return result;
}
/**
* 删除整个目录的全部图片
* filePath 要删除的目录路径
*/
public static boolean deleteImage(String filePath) {
try {
File file = new File(filePath);
File[] files = file.listFiles();
for(int i=0;i<files.length;i++) {
try {
//系统文件不删除
if(!(files[i].getName()).equalsIgnoreCase("Thumbs.db")) {
if(files[i].isFile()) {
files[i].delete();
} else if(files[i].isDirectory()) {
files[i].delete();
} else {
files[i].delete();
}
}
} catch (RuntimeException e) {;
}
}
return true;
} catch (RuntimeException e) {
return false;
}
}
/**
* 保存网络上的图片到指定目录
* filePath 要保存到本地服务器的目录
* imagePath 网络图片的UIL地址
*/
public static boolean saveImage(String filePath,String imagePath) {
try {
if(imagePath.length()>1024 || imagePath.equals("")) {
return false;
}
String fileName = imagePath.substring(imagePath.lastIndexOf("/")+1,imagePath.length());
filePath = filePath+fileName;
URL url = null;
try {
url = new URL(imagePath);
} catch(Exception e) {
return false;
}
FilterInputStream in=(FilterInputStream) url.openStream();
File fileOut=new File(filePath);
FileOutputStream out=new FileOutputStream(fileOut);
byte[] bytes=new byte[1024];
int c;
while((c=in.read(bytes))!=-1) {
out.write(bytes,0,c);
}
in.close();
out.close();
return true;
} catch(Exception e) {
return false;
}
}
/**
* 写入日志
* filePath 日志文件的路径
* code 要写入日志文件的内容
*/
public static boolean print(String filePath,String code) {
try {
File tofile=new File(filePath);
FileWriter fw=new FileWriter(tofile,true);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter pw=new PrintWriter(bw);
System.out.println(getDate()+":"+code);
pw.println(getDate()+":"+code);
pw.close();
bw.close();
fw.close();
return true;
} catch (IOException e) {
return false;
}
}
/**
* 判断是不是合法手机
* handset 手机号码
*/
public static boolean isHandset(String handset) {
try {
if(!handset.substring(0,1).equals("1")) {
return false;
}
if (handset==null || handset.length()!=11) {
return false;
}
String check = "^[0123456789]+$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(handset);
boolean isMatched = matcher.matches();
if(isMatched) {
return true;
} else {
return false;
}
} catch (RuntimeException e) {
return false;
}
}
}
相关推荐
java 工具类 项目开发常用方法,如:字符转换函数,字符处理,数组相关的处理函数
根据提供的文件信息,“Java项目开发实战”这一主题主要聚焦于Java项目的实际开发过程与技巧,适合初学者作为入门指南来了解Java项目开发的基本流程和技术要点。下面将从多个角度深入探讨这一主题涉及的关键知识点。...
在《Java项目开发实战案例》这个资源中,我们聚焦于Java技术在实际项目中的应用,通过具体的案例来深入了解系统开发的全过程。这个实战教程旨在帮助开发者掌握从需求分析到项目落地的各项技能,涵盖数据库设计、前后...
综上所述,“JAVA项目开发案例全程实录(超级高清).PDF”不仅涵盖了一般Java项目的开发流程和技术栈介绍,还提供了实际案例分析和问题解决方法等内容,对于想要深入了解Java项目开发的读者来说,是一份非常有价值的...
在学习这些知识点的过程中,PPT可能会提供详细的代码示例、案例分析以及问题解决策略,帮助学习者逐步提高Java项目开发的能力。此外,PPT中的每一页都可能包含小结和习题,以巩固学习效果。通过这样的学习计划,学习...
在Java项目开发中,全程实录通常意味着从项目的初期规划、设计、编码到测试和部署的完整过程。这个压缩包文件“TM - 副本”可能包含了这样的一个实际项目的所有源代码,为学习者提供了深入理解Java项目开发流程的...
最后,值得一提的是,学习Java开发词汇并不仅仅是为了应对考试或者面试,更重要的是将其应用在实际的软件开发项目中。例如,开发一个Android应用程序,就需要应用到Java词汇中的Activity、Fragment、Intent、Service...
JAVA开发常用工具安装包 Java是一种广泛应用于软件开发的编程语言,为了提高开发效率和质量,开发者需要安装和配置各种开发工具。以下是JAVA开发常用工具安装包的详细介绍: Eclipse Eclipse是最流行的Java开发...
下面,我们将深入探讨Java项目开发的关键知识点: 1. **Java简介**:Java是一种多平台、面向对象的编程语言,由Sun Microsystems(现已被Oracle收购)于1995年推出。它的设计目标是“一次编写,到处运行”,这得益...
这里,我们重点讨论的是在项目中经常使用的Java封装类,这些类通常是开发人员为了简化常见任务而创建的工具类或者实用类。下面,我们将详细探讨String类的封装、分页封装、Servlet的封装以及其他一些常见的封装实践...
《亮剑Java项目开发案例导航》一书中包含了多个实战项目案例,如在线商城系统、博客平台、论坛系统等。通过这些案例的学习,读者不仅可以掌握Java Web开发的理论知识,还能深入了解项目开发的全过程,包括需求分析、...
《Java项目开发全程实录》是一本专注于Java编程和项目实践的书籍,其源代码提供了丰富的实例和案例,帮助读者深入理解Java在实际项目中的应用。这本书的核心目标是引导读者从理论到实践,掌握Java开发的全过程,包括...
《Java项目开发全程实录》这一本书从开发背景、需求分析、系统功能分析、数据库分析、数据库建模、网站开发和网站发布或者程序打包与运行,每一过程都进行了详细的介绍。 目 录 第1章 进销存管理系统(Swing+SQL ...
在Java项目开发中,以下是一些关键知识点: 1. **基础语法与面向对象编程**:Java是一种强类型、面向对象的语言,理解类、对象、封装、继承、多态等概念是Java编程的基础。 2. **异常处理**:Java中的异常处理机制...
Java项目开发常用工具包,其中主要包括:Assert.java BufferedImageLuminanceSource.java CipherUtil.java ClientConst.java CodeUtil.java ComputeUtil.java DataUtils.java DateUtils.java Digests.java Encodes....
在Java项目开发领域,实践是检验知识掌握程度的最好方式。本"Java项目开发案例"提供了丰富的实战经验,涵盖了多种类型的项目,旨在帮助开发者提升Java编程技能和项目实施能力。以下将详细介绍这些项目的类别和可能...
《亮剑Java Web项目开发案例导航》是一本深入实践的编程教材,主要针对Java Web开发进行详尽的实例解析。源码的提供使得读者能够更好地理解书中的理论知识,并通过实际操作来提升技能。以下是对这个项目开发案例的...
在Java项目开发中,我们经常会遇到各种技术和概念,这些都在"Java项目开发全程实录-源代码"中有所体现。这个资源提供了从头到尾的项目构建过程,旨在帮助开发者深入理解Java编程语言以及相关技术栈的应用。让我们...
在本Java案例详解1精通Java项目开发中,我们将深入探讨如何使用Java技术构建高效、稳定的企业信息系统。这个案例主要基于Java编程语言,并结合SQL2000数据库管理系统,利用MyEclipse开发工具来实现。以下将详细介绍...