Cover source: Moments of Friends

Author: A lie

The road of learning, many people walk together, grow together, I think is the greatest joy on the road to the distance. ‘

One, foreword

I’ll make a copy of this photo.

Native Java code IO operation +

package com.hutool;
import java.io.*;
/ * * *@Author: crush
 * @Date: 2021-05-20 19:21
 * version 1.0
 */
public class HuToolIoDemo {
    public static void main(String[] args) throws IOException {
      FileInputStream inputStream= new  FileInputStream(new File("E:\\good_image\\image\\1.jpg"));
      FileOutputStream outputStream = new FileOutputStream(new File("E:\\good_image\\2.jpeg"));
      // Define a buffer
        byte[] b=new byte[1024];
        int len=0;
        while (true){
            len=inputStream.read(b);
            if (len==-1) {
                break;
            }
            outputStream.write(b,0,len); } inputStream.close(); outputStream.close(); }}Copy the code

Yes again to set the buffer, again to write a loop to read one by one.

3. After the introduction of huTool

But with the introduction of huTool, the code becomes three lines.

package com.hutool;

import cn.hutool.core.io.IoUtil;

import java.io.*;

/ * * *@Author: crush
 * @Date: 2021-05-20 19:21
 * version 1.0
 */
public class HuToolIoDemo {
    public static void main(String[] args) throws IOException {
      FileInputStream inputStream= new  FileInputStream(new File("E:\\good_image\\image\\1.jpg"));
      FileOutputStream outputStream = new FileOutputStream(new File("E:\\good_image\\2.jpeg")); IoUtil.copy(inputStream,outputStream); IoUtil.close(outputStream); IoUtil.close(inputStream); }}Copy the code

It just feels so good.

Hutool has a lot of good things to use, conversion type which is also very good, I suggest to try.

If you use a lot of huTool tools.

You can use the following dependency as I did. All of them.

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.6.5</version>
</dependency>
Copy the code

Some simple and common type conversions

package com.hutool;

import cn.hutool.core.convert.Convert;
import java.util.Date;
import java.util.List;
/ * * *@Author: crush
 * @Date: 2021-05-20 19:43
 * version 1.0
 */
public class HuToolDemo2 {

    public static void main(String[] args) {

        // Convert to a string
        int a=1;
        System.out.println(Convert.toStr(a));

        long[] b={1.2.3.4.5};
        System.out.println(Convert.toStr(b));

        // Convert the result of the specified type array to an Integer array
        String[] sss={"1"."2"."3"."4"."5"};
        Integer[] integers = Convert.toIntArray(sss);

        // String transfer object
        String str1="2020-12-12";
        System.out.println(Convert.toDate(str1));

        String str2="2020/12/12";
        System.out.println(Convert.toDate(str2));

        String str3="2020.12.12";
        System.out.println(Convert.toDate(str3));

        // Turn an array into a collection
        String [] aaa={"111"."222"."Learning HuTool kit for the first time"."It's really powerful."}; List<String> objects = (List<String>) Convert.toList(aaa); System.out.println(objects); }}Copy the code

Talk to yourself

The more you learn, the more fun you find.