riku
2022-06-17 fd8c31dc5a0c0372d867335283f0b5272d667236
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
package cn.flightfeather.supervision.infrastructure.utils
 
import java.io.File
import java.io.FileOutputStream
 
 
class FileUtil {
    @Throws(Exception::class)
    fun uploadFile(file: ByteArray, filePath: String, fileName: String) {
        val targetFile = File(filePath)
        if (!targetFile.exists()) {
            targetFile.mkdirs()
        }
        val out = FileOutputStream(filePath + fileName)
        out.write(file)
        out.flush()
        out.close()
    }
 
    /**
     * 获取文件名
     */
    fun getFileName(path: String?): String {
        if (!path.isNullOrEmpty()) {
            val dot = path!!.lastIndexOf('/')
            if (dot > -1 && dot < path.length - 1) {
                return path.substring(dot + 1)
            }
        }
        return ""
    }
}