1.得到系统现在时间并按格式输出的函数
//返回时间字符串
public String getCurrentTime()
{
SimpleDateFormat sdf = new SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE);
sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date());
}
最前面包括import java.text.SimpleDateFormat;
2.熟练运用tostring()
3.substring(str,a,b)
str 是你要截取的字符串所在的字符串;a是从哪里开始截取;b是从哪开始不截取了
4.读文件
FileReader fr = new FileReader("UserInfo.txt");
BufferedReader br = new BufferedReader(fr);
写文件
FileWriter fw = new FileWriter("userInfo.txt");
BufferedWriter bw = new BufferedWriter(fw);
对br bw进行操作
5.Scanner in = new Scanner(str1).useDelimiter("#");
这个语句能使in.next()遇到#不读了 代替了原来的遇到“ ”不读了
6.正则表达式
//判断密码每位是否相同
public boolean isright(String key)
{
String str = key.substring(0,1) + "{" + key.length() + "}";
if(key.matches(str))
return false;
else
return true;
}
这里str就是正则表达式,运用了matches函数进行比较
7.范型列表
ArrayList<String> strList = new ArrayList<String>();
和数组的使用方式差不多
8.newLine()把光标移到下一行
9.in.next()如果读不到内容就会抛出异常