public class FileUtil extends Object
| Constructor and Description |
|---|
FileUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
appendFilePath(String original,
String append) |
static void |
copyFile(String from,
String to)
文件 zero copy 复制
|
static Path |
copyInputStreamToTempFile(InputStream in,
String prefix,
String suffix)
将输入流写入文件
|
static Path |
createTempFile(String prefix,
String suffix)
创建临时文件
|
static BufferedInputStream |
getBufferedInputStream(String path) |
static BufferedReader |
getBufferedReader(String path) |
static byte[] |
getFileBytes(String path) |
static FileInputStream |
getFileInputStream(String path) |
static FileReader |
getFileReader(String path) |
static String |
getMimeType(String path)
获取文件mime type
|
static String |
getProjectClassPath() |
static String |
getProjectPath() |
static DataInputStream |
getResourceDataInputStream(String path) |
static FileInputStream |
getResourceFileInputStream(ClassLoader classLoader,
String path) |
static InputStream |
getResourceInputStream(ClassLoader classLoader,
String path)
默认则是从ClassPath根下获取,path不能以'/'开头,最终是由ClassLoader获取资源。
|
static InputStream |
getResourceInputStream(Class clazz,
String path)
path 不以'/'开头时默认是从此类所在的包下取资源,以'/'开头则是从ClassPath(Src根目录)根下获取。
其只是通过path构造一个绝对路径,最终还是由ClassLoader获取资源。
|
static boolean |
initDirectory(File file) |
static boolean |
initFile(File file) |
static String |
saveToTempDir(byte[] bytes,
String contentType) |
public static InputStream getResourceInputStream(Class clazz, String path)
clazz - xxxpath - xxxpublic static InputStream getResourceInputStream(ClassLoader classLoader, String path)
classLoader - xxxpath - xxxpublic static FileInputStream getResourceFileInputStream(ClassLoader classLoader, String path) throws URISyntaxException, FileNotFoundException
public static FileInputStream getFileInputStream(String path) throws FileNotFoundException
FileNotFoundExceptionpublic static DataInputStream getResourceDataInputStream(String path) throws FileNotFoundException
FileNotFoundExceptionpublic static FileReader getFileReader(String path) throws FileNotFoundException
FileNotFoundExceptionpublic static BufferedInputStream getBufferedInputStream(String path) throws FileNotFoundException
FileNotFoundExceptionpublic static BufferedReader getBufferedReader(String path) throws FileNotFoundException
FileNotFoundExceptionpublic static byte[] getFileBytes(String path) throws IOException
IOExceptionpublic static String getProjectClassPath()
public static String getProjectPath()
public static String saveToTempDir(byte[] bytes, String contentType) throws IOException
IOExceptionpublic static void copyFile(String from, String to) throws IOException
from - xxxto - xxxIOException - xxxpublic static String getMimeType(String path) throws IOException
path - xxxIOException - xxxpublic static Path createTempFile(String prefix, String suffix) throws IOException
prefix - xxxsuffix - xxxIOException - xxxpublic static Path copyInputStreamToTempFile(InputStream in, String prefix, String suffix) throws IOException
in - xxxprefix - xxxsuffix - xxxIOException - xxxpublic static boolean initFile(File file) throws IOException
IOExceptionpublic static boolean initDirectory(File file) throws IOException
IOExceptionCopyright © 2018. All rights reserved.