FileUtils

public class FileUtils

Properties

Link copied to clipboard
public final static int FILE_SCHEME_LENGTH

Functions

Link copied to clipboard
public static File byte2File(Array<byte> buf, String filePath, String fileName)
Generates a file based on the byte array
Link copied to clipboard
public static Array<byte> contentFile2byte(Context context, Uri uri)
Retrieves the byte array of the specified file, which must start with content.
Link copied to clipboard
public static File convertBitmap2File(Bitmap bm, String dir, String name)
Convert image to file
Link copied to clipboard
public static boolean copyFile(Context context, Uri srcUri, String desPath)

public static File copyFile(File src, String path, String name)
Copy a file
public static boolean copyFile(String srcPath, String path, String name)
Copy files, only supports files starting with 'file'
Link copied to clipboard
public static boolean copyFileToInternal(Context context, Uri srcUri, String desPath, String name)
Link copied to clipboard
public static Array<byte> file2byte(File file)
Retrieves the byte array of the specified file.
public static Array<byte> file2byte(Context context, Uri uri)
Link copied to clipboard
public static String generateKey()
Link copied to clipboard
public static Array<byte> getByteFromUri(Uri uri)
Reads a file in bytes, commonly used for reading binary files such as images, audio, video, etc.
Link copied to clipboard
public static String getCacheDirsPath(Context context, String dir)
Retrieves the cache storage path, such as /sdcard/Android/data/<package name>/cache/<dir>
Link copied to clipboard
public static String getCachePath(Context context)
Retrieves the cache storage path, such as /sdcard/Android/data/<package name>/cache
public static String getCachePath(Context context, String dir)
Retrieves the cache storage path, such as /sdcard/Android/data/<package name>/cache/<dir>
Link copied to clipboard
public static File getExternalCacheDir(Context context)
// For versions below 9.
Link copied to clipboard
public static FileInfo getFileInfoByFile(File file)
Retrieves the file name, size, and type from the file
Link copied to clipboard
public static FileInfo getFileInfoByUri(Context context, Uri uri)
Retrieves the file name, size, and type from the URI.
Link copied to clipboard
public static InputStream getFileInputStream(String path)
Creates an input stream pointing to the file, reading its contents into memory.
public static InputStream getFileInputStream(Context context, Uri uri)
Link copied to clipboard
public static String getFileKey(Message message)
Retrieves the key for media messages, used for handling messages such as images, videos, and GIFs.
Link copied to clipboard
public static long getFileLengthWithUri(Context pContext, Uri pUri)
Gets the file length.
Link copied to clipboard
public static String getFileNameWithPath(String path)
Retrieves the file name based on the file path
Link copied to clipboard
public static long getFileSize(File file)
Get the size of the specified file
Link copied to clipboard
public static String getFileTypeFromByteData(Array<byte> data)
Link copied to clipboard
public static String getFileTypeFromInputStream(InputStream inputStream)
Retrieves the file type from the input stream
Link copied to clipboard
public static String getInternalCachePath(Context context, String dir)
Get the app cache storage path data/data/<package name>/cache/<dir>
Link copied to clipboard
public static String getJsonOutPath(Context context)
Link copied to clipboard
@Deprecated()
public static String getMediaDownloadDir(Context context)
Get the storage path of media files
public static String getMediaDownloadDir(Context context, String dir)
Get the storage path for media files
Link copied to clipboard
public static String getStringFromFile(String path)
Get file data
Link copied to clipboard
public static String getSuffix(Uri srcUri)
Get the suffix of the Uri
public static String getSuffix(String path)
Get the URI suffix
Link copied to clipboard
public static String getTempFileMD5(Context context, int messageId)
Retrieves the MD5 key for file resumption, used to identify the file being downloaded.
public static String getTempFileMD5(Context context, String tag)
Retrieves the temporary filename for resumable file download, used to identify the file being downloaded.
Link copied to clipboard
public static String getTempFilePath(Context context, int messageId)
Get the temporary file storage path for resumable upload
public static String getTempFilePath(Context context, String id)
Get the temporary file storage path for resumable uploads
Link copied to clipboard
public static String getUrlFileName(String url, String fileName)
Link copied to clipboard
public static boolean isFileExistsWithUri(Context pContext, Uri pUri)
Checks if the file exists.
Link copied to clipboard
public static boolean isValidateLocalUri(Uri pUri)
Checks if the file URI scheme starts with file or content.
Link copied to clipboard
public static int readPictureDegree(Context context, String path)
Reads the rotation angle of an image
Link copied to clipboard
public static void removeFile(String path)
Delete File
Link copied to clipboard
public static String sanitizeFilename(String displayName)
Cleans the file name to prevent path traversal attacks
Link copied to clipboard
public static void saveFile(String str, String filePath)
Stores the string at the specified path
Link copied to clipboard
public static boolean uriStartWithContent(Uri srcUri)
Checks whether the file URI scheme starts with content.
Link copied to clipboard
public static boolean uriStartWithFile(Uri pUri)
Checks if the file Uri scheme starts with file and if the file Uri length exceeds 7
Link copied to clipboard
public static void writeByte(Uri uri, Array<byte> data)
Writes the byte array sequentially to the file output stream.