18045010223
2025-07-07 4d55075574ff1d55c1f56f89f5f3f95889258914
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cn.org.hentai.jtt1078.util;
 
import java.io.*;
 
/**
 * Created by matrixy on 2019/8/25.
 */
public final class FileUtils
{
    public static void writeFile(File file, byte[] data)
    {
        writeFile(file, data, false);
    }
 
    public static void writeFile(File file, byte[] data, boolean append)
    {
        FileOutputStream fos = null;
        try
        {
            fos = new FileOutputStream(file, append);
            fos.write(data);
        }
        catch(Exception ex)
        {
            throw new RuntimeException(ex);
        }
        finally
        {
            try { fos.close(); } catch(Exception e) { }
        }
    }
 
    public static byte[] read(File file)
    {
        FileInputStream fis = null;
        try
        {
            fis = new FileInputStream(file);
            return read(fis);
        }
        catch(Exception ex)
        {
            throw new RuntimeException(ex);
        }
        finally
        {
            try { fis.close(); } catch(Exception e) { }
        }
    }
 
    public static byte[] read(InputStream fis)
    {
        ByteArrayOutputStream baos = null;
        try
        {
            baos = new ByteArrayOutputStream(1024);
 
            int len = -1;
            byte[] block = new byte[1024];
            while ((len = fis.read(block)) > -1)
            {
                baos.write(block, 0, len);
            }
 
            return baos.toByteArray();
        }
        catch(Exception ex)
        {
            throw new RuntimeException(ex);
        }
    }
 
    public static void readInto(File file, OutputStream os)
    {
        FileInputStream fis = null;
        try
        {
            int len = -1;
            byte[] block = new byte[1024];
            fis = new FileInputStream(file);
            while ((len = fis.read(block)) > -1)
            {
                os.write(block, 0, len);
                os.flush();
            }
        }
        catch(Exception ex)
        {
            throw new RuntimeException(ex);
        }
        finally
        {
            try { fis.close(); } catch(Exception e) { }
        }
    }
}