目录

Life in Flow

知不知,尚矣;不知知,病矣。
不知不知,殆矣。

URL、URLConnection

URL  URL 类 java.net 包中定义了 URL 类 @Test public void urlTesting() throws IOException { URL url = new URL("http://api.xdclass.net:8081/pub/api/v1/web/find_ad_by_id?id=1"); //主机地址 System.out.println("getHost="+ url.getHost());//api.xdclass.net //协议 System.out.println("getProtocol="+ url.getProtocol());//http //端口 System.out.println("getPort="+ url.getPort());//8081 //路径(接口) System.out.println("url.getPath="+ url.getPath());// /pub/api/v1/web/find_ad_by_id //请求参数 System.out.println("url.getQuery="+ ur....

Enum

枚举类的使用场景  在数学和计算机科学理论中,⼀个集的枚举是列出某些有穷序列集的所有成员的程 序,或者是 ⼀种特定类型对象的计数。 枚举类型是 Java 5 中新增特性的 ⼀部分,它是 ⼀种特殊的数据类型 定义枚举类型时使 ⽤的关键字是 enum,与 class 关键字类似,但前者是定义枚举类型,后者 是定义类类型 注意: 枚举值 ⼀般是 ⼤写的字母,多个值之间以逗号分隔 不使用枚举类型时(定义常量) //定义⼀个⼀周⾥⾯的每天 public class DayConstant { public static final int MONDAY =1; public static final int TUESDAY=2; public static final int WEDNESDAY=3; public static final int THURSDAY=4; public static final int FRIDAY=5; public static final int SATURDAY=6; public static final int SUNDAY=7; } 使用枚举....

常用类

Math @Test public void randomHeroTesting() { //计算平⽅根 System.out.println(Math.sqrt(16)); //计算⽴⽅根 System.out.println(Math.cbrt(8)); //两个数的最⼤,⽀持int, long, float,double System.out.println(Math.max(2.9,4.5)); System.out.println(Math.min(2.9,4.5)); //ceil向上取整,更⼤的值⽅向靠拢, 中⽂是天花板 System.out.println(Math.ceil(19.7)); System.out.println(Math.ceil(-20.1)); //floor向下取整,更⼩的值⽅向靠拢,中⽂是地板意思 System.out.println(Math.floor(19.7)); System.out.println(Math.floor(-20.1)); List<String> list = Arrays.asList("Pandare....

Date-Time、DateTimeFormatter

时区  整个地球分为 ⼆ ⼗四时区,每个时区都有 ⾃ ⼰的本地时间。为了统 ⼀,使 ⽤ ⼀个统 ⼀的时间,称为全球标准时间(UTC, Universal Time Coordinated)。  TC 与格林尼治平均时(GMT, Greenwich Mean Time,也翻译成:格林威治标准时间)差不多一样。  CST(北京时间),北京时间,China Standard Time,中国标准时间。在时区划分上,属东八区,⽐协调世界时早 8⼩时,记为 UTC+8。  时间戳:⾃ 1970 年 1 ⽉ 1 ⽇(08:00:00 GMT)⾄当前时间的总秒数,它也被称为 Unix 时 间戳(Unix Timestamp),⼴泛的运 ⽤在知识产权保护、 合同签字、 ⾦融帐务、 电 ⼦报价投 标、 股票交易等 ⽅ ⾯。 格式多种:2050-10-31 10:11:11、 2050/10/31 10/10:10 年、⽉、⽇、周⼏等 Date 类  java.util 包提供了 Date 类来封装当前的 ⽇期和时间。 构造函数 //当前时间 Date() //从1970年1⽉1⽇起的毫秒数作为参数 Dat....

IO流异常处理

JDK6 /** * try{}catch{}finally{释放资源} * * @throws IOException */ @Test public void tryCatchTesting2() throws IOException { BufferedInputStream bis = null; BufferedOutputStream bos = null; try { FileInputStream inputStream = new FileInputStream("C:\\Users\\Ryzen-7-3800X\\Pictures\\Camera Roll\\test\\1\\1.txt"); bis = new BufferedInputStream(inputStream); FileOutputStream outputStream = new FileOutputStream("C:\\Users\\Ryzen-7-3800X\\Pictures\\Camera Roll\\test\\1\\222.txt"); bos = new BufferedOutp....

Reader、Writer

IO 流体系图 Reader  Reader 是输 ⼊字符流的 ⽗类,它是 ⼀个抽象类, 部分库不推荐使 ⽤ Reader/Writer。 常见方法 //⼀个字符⼀个字符的读,只能⽤来操作⽂本(不能写图⽚ ⾳频 视频) int read() //从输⼊字符流中读取⼀定数量的字符,并将其存储在缓冲区数组cbuf中, 返回实际读取的字符 数,如果已经到达流末尾⽽没有可⽤的字节,则返回-1 int read(char cbuf[]) //关闭输⼊流并释放与该流关联的系统资源 void close() throws IOException FileReader  用来读取字符 ⽂件的实现类。 /** * 读取中⽂显示出来, java运⾏时采⽤utf16编码,多数汉字占2个字节,⼀个char就够,少数占4个字节,需要两个char来表示 */ @Test public void readerCharArrayTesting() throws IOException { String filePath = "C:\\Users\\Ryzen-7-3800X\\Pictures\\Camera R....

InputStream、OutputStream、Buffer

I/O 输出流:程序(内存)---> 外界设备 输 ⼊流:外界设备---> 程序(内存) 处理数据类型分类 字符流:处理字符相关,如处理 ⽂本数据(如 txt⽂件), Reader/Writer 字节流: 处理字节相关,如声 ⾳或者图 ⽚等 ⼆进制,InputStream/OutputStream 字符流和字节流区别  字节流以字节(8bit)为单位,字符流以字符为单位,根据码表映射字符,⼀次可能读多个字节。 字节流可以处理 ⼏乎所有 ⽂件,字符流只能处理字符类型的数据。 InputStream  InputStream 是输 ⼊字节流的 ⽗类,它是 ⼀个抽象类(⼀般 ⽤他的 ⼦类) 常见方法 //讲解:从输⼊流中读取单个字节,返回0到255范围内的int字节值,字节数据可直接转换为int类 型, 如果已经到达流末尾⽽没有可⽤的字节,则返回-1 int read() //从输⼊流中读取⼀定数量的字节,并将其存储在缓冲区数组buf中, 返回实际读取的字节 数,如果已经到达流末尾⽽没有可⽤的字节,则返回-1 int read(byte[] buf) //从输⼊流中....