反射io流正则网编MySqlJavaWebAndroid等等等等等等等等等等等等等等等等等~~~~~~
Posted 怪歌
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了反射io流正则网编MySqlJavaWebAndroid等等等等等等等等等等等等等等等等等~~~~~~相关的知识,希望对你有一定的参考价值。
Java-android
- BasicsTwo(java)
- -----------------------------------------
- BasicsThree(java~Web)
- --------------------------------------
- -----------------------------------------
- PhaseOne (Android)
- -----------------------------------------
- One(Android)
- -------------------------------
- PhaseTwo(Android)
BasicsTwo(java)
反射
修改方法
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException
ArrayList<String> list = new ArrayList<>();
list.add("oiuoaisduf");
list.add("asljkdf");
Class<? extends ArrayList> aClass1 = list.getClass(); //通过对象名获取class
Class<ArrayList> aClass2 = ArrayList.class; //通过集合获取class
Class<?> aClass3 = Class.forName("java.util.ArrayList"); //通过包和类名获取class
Method add = aClass1.getDeclaredMethod("add", Object.class);
add.invoke(list,5.21345689756);
add.invoke(list,123456789);
add.invoke(list,5.21345689756);
System.out.println(list);
修改值
private static HashMap<String,User> map = new HashMap<>();
static
User no1 = new User("wangyide", "5210");
User no2 = new User("aaa", "123");
map.put("user1",no1);
map.put("user2",no2);
public static void main(String[] args)
Class<HashMap> hashMapClass = HashMap.class;
Collection<User> values = map.values();
Field[] declaredFields = hashMapClass.getDeclaredFields();
java正则验证
正则表达式是用于判定文本格式的,一般用于判断用户添加信息的格式,或登录注册时使用的。
public class Main
public static void main(String[] args)
Scanner scanner = new Scanner(System.in);
while (true)
System.out.println("请输入QQ邮箱:");
String email = scanner.next();
//调用正则判断方法
boolean regex = regex(email);
//如果不对则输出错误信息 正确则跳出
if (regex)
System.out.println("格式正确");
break;
else
System.out.println("格式不正确");
private static boolean regex(String email)
//正则表达式解析对象Pattern 参数为正则表达式
Pattern compile = Pattern.compile("^\\\\d+@\\\\w+.com(.cn)?$");
//pattern对象获取匹配数据对象 参数为输入的邮箱
Matcher matcher = compile.matcher(email);
boolean b = matcher.find();
return b;
运行效果 ↓↓↓↓↓
简易IO(面向文件的增删改查)
public class Demo
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws Exception
start();
private static void start() throws Exception
System.out.println("1.文件目录操作");
System.out.println("0.退出");
System.out.println("请输入您的选择:");
switch (scanner.nextInt())
case 1:
System.out.println("1:D:\\\\ 2.C:\\\\");
System.out.println("请选择路径");
File file = new File("D:\\\\");
File file1 = new File("C:\\\\");
if (scanner.nextInt()==2)
show(file1);
else
show(file);
start();
break;
case 0:
System.out.println("谢谢使用");
System.exit(0);
break;
default:
System.out.println("输入错误,请重新输入");
start();
break;
private static void show(File file1) throws Exception
if (file1.isDirectory())
File[] files = file1.listFiles();
for (File s:
files)
System.out.println(s.getName());
System.out.println("1.继续打开 2.创建文件 3.创建文件夹 4.删除文件或文件夹 5.返回上一级 0.退出");
int i = scanner.nextInt();
if (i==1)
System.out.println("请输入文件名:");
String name = scanner.next();
for (File s:
files)
if (name.equals(s.getName()))
show(s);
else if (i==2)
System.out.println("请输入文件名(加后缀名如:.txt):");
String name = scanner.next();
File file = new File(file1+"/"+name);
file.createNewFile();
else if (i==3)
System.out.println("请输入文件夹名:");
String name = scanner.next();
File file = new File(file1+"/"+name);
file.mkdir();
else if (i==4)
System.out.println("请输入要删除的文件夹:");
String name = scanner.next();
File file6 = new File(file1+"/"+name);
deleteFile(file6);
System.out.println("删除成功");
else if (i==0)
System.exit(0);
else if (i==5)
String path = file1.getPath();
File parentFile = file1.getParentFile();
show(parentFile);
else
System.out.println("输入错误");
private static void deleteFile(File file)
if (file.exists())
if (file.isFile())
file.delete();
else
if (file.length()==0)
file.delete();
File[] files = file.listFiles();
for (File f:
files)
if (f.isFile())
f.delete();
else
deleteFile(f);
file.delete();
else
System.out.println("不存在此文件");
IO流
缓冲流
缓冲流是用来优化字节或字符流的,
一般字符流比字节流读写要快,但字节流可读取写入除字符以外的数据
序列化流
序列化流可以读取或写入对象,但直接写入会造成乱码
转换流
转换流用来将字节流和字符流相互替换
一般读取JSON-url中的数据获取的流为字节流
一般编程会把字节流转换为字符流
加上缓冲流达到最佳效果
(文件字节输入流)FileInputStream
FileInputStream fileInputStream = new FileInputStream("字节流.txt");
byte[] bs = new byte[1024]; //用来存 读到的内容
int len = fileInputStream.read(bs); //len:读到的长度
String string = new String(bs,0,len);
System.out.println(string);
fileInputStream.close();
(文件字节输出流) FileOutputStream
FileOutputStream fileOutputStream = new FileOutputStream("字节流.txt");
fileOutputStream.write("你好".getBytes());
fileOutputStream.close();
(文件字符输入流)FileReader
FileReader fileReader = new FileReader("字符流.txt");
char[] cs = new char[1024]; //保存读到的内容
int len = fileReader.read(cs);
String string = new String(cs,0,len);
System.out.println(string);
fileReader.close();
(文件字符输出流)FileWriter
FileWriter fileWriter = new FileWriter("字符流.txt");
fileWriter.write("你好");
fileWriter.close();
【字节流复制(边读边写)】
//读
FileInputStream fileInputStream = new FileInputStream("D:\\\\install\\\\ideaIU-2020.1.3.exe");
//写
FileOutputStream fileOutputStream = new FileOutputStream("D:/aaa.exe");
byte[] bs = new byte[1024]; //存储读取到的内容
while (true)
int len = fileInputStream.read(bs);
if (len==-1)
break;
fileOutputStream.write(bs, 0, len);
fileInputStream.close();
fileOutputStream.close();
(缓冲输出字符流)BufferedWriter
FileWriter fileWriter = new FileWriter("缓冲字符流.txt");
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write("缓冲字符流,你好");
bufferedWriter.close();
(缓冲输入字符流) BufferedReader
FileReader fileReader = new FileReader("缓冲字符流.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
// char[] cs = new char[1024];
//
// int len = bufferedReader.read(cs);
//
// String string = new String(cs, 0, len);
// System.out.println(string);
以上是关于反射io流正则网编MySqlJavaWebAndroid等等等等等等等等等等等等等等等等等~~~~~~的主要内容,如果未能解决你的问题,请参考以下文章