IO
byte[] bytes=Files.readAllBytes(File fle):将文件返回字节数组
Paths.get(path):通过知道文件路径,返回文件
String path = "C:\\Users\\ThinkPad\\Desktop\\ihrm\\day11\\资源\\照片\\001.png";
byte[] bytes = Files.readAllBytes(Paths.get(path));
String image = Base64Util.encode(bytes);
Map
map.computeIfAbsent()
1、首先会判断map中是否有对应的Key
2.1、如果没有对应的Key,则会创建一个满足Value类型的数据结构放到Value的位置中;
2.2、如果有对应的Key,则会操作该Key对应的Value.
public static void main(String[] args) {
HashMap<String, List<Integer>> map = new HashMap<>();
/**
* 首先,Map中没有 "hadoop" 这个Key,所以会创建一个满足Value类型的数据结构放入到Key对应的Value中
* 随后对该Value对应的值进行操作,如下代码是:list.add(1)
*/
map.computeIfAbsent("hadoop", key -> new ArrayList<>()).add(1);
System.out.println(map);//{hadoop=[1]}
/**
* Map中已经有 "hadoop" 这个 Key,所以会操作该Key对应的一个Value
* 如下代码,对Key对应的Value进行 list.add(2) 这个操作
*/
map.computeIfAbsent("hadoop", key -> new ArrayList<>()).add(2);
System.out.println(map);//{hadoop=[1, 2]}
}
Double.IntValue()方法可以将double转换为int 。
public class Main{
public static void main(String []args){
double doubleValue = 82.14; // 82.14
Double doubleValueObject = new Double(doubleValue);
int intValue = doubleValueObject.intValue(); // 82
}
}
DecimalFormat:用于格式化十进制数字
DecimalFormat df1 = new DecimalFormat("0.0");
DecimalFormat df2 = new DecimalFormat("#.#");
DecimalFormat df3 = new DecimalFormat("000.000");
DecimalFormat df4 = new DecimalFormat("###.###");
System.out.println(df1.format(12.34)); //12.3
System.out.println(df2.format(12.34)); //12.3
System.out.println(df3.format(12.34)); //012.340
System.out.println(df4.format(12.34)); //12.34